導航:首頁 > 編程知識 > vb編程怎麼找mac地址

vb編程怎麼找mac地址

發布時間:2023-02-12 18:51:35

㈠ VB如何獲取網卡MAC地址,請給出代碼

獲取mac地址,其實可以換一個思路,通過獲取命令ipconfig /all 的內容,然後通過字元串匹配就可以獲得了。

㈡ 用VB獲取MAC地址

Private Sub Form_Load()
Dim Mac
strComputer = "."
Mac = ""

'獲得MAC信息

Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!//" & strComputer & "/root/cimv2")'''加上這個
Set colItems = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled=TRUE")
For Each objItem In colItems
Mac = Mac + " " + objItem.macaddress
Next
TeMac.Text = Replace(Trim(Mac), ":", "-")

strComputer = "."
Set objWMI = GetObject("winmgmts://" & strComputer & "/root/cimv2")
Set colIP = objWMI.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")

For Each Ip In colIP
If Not IsNull(Ip.ipaddress) Then
For i = LBound(Ip.ipaddress) To UBound(Ip.ipaddress)
'Mac = Ip.macaddress(I)objObject.DNSHostName
If Ip.ipaddress(i) = "0.0.0.0" Then
Else

TeIp.Text = Trim(TeIp.Text + " " + Ip.ipaddress(i))
End If
'MsgBox "IP 地址:" & IP.ipaddress(I) & Chr(10) & _
"網卡類型:" & IP.Description(I) & Chr(10) & _
"網卡地址:" & IP.macaddress(I)
Next
End If
Next
End Sub

㈢ VB6.0 怎麼獲得本機的IP和mac地址

gethostname 獲取本機名字,gethostbyname 通過前面的名字獲取主機具體信息,包括IP地址。MAC地址可以用 Netbios,以上用到的函數都是WIN32 API,具體代碼請留聯系方式(email或者企鵝)也可以自己網路有現成的VB代碼

㈣ 用vb.net如何取得mac地址

剛剛我自己寫了一段是引用System.net來做的我不喜歡用WMI主要是查出來的信息不準確,下面我附上源碼希望可以加分給我

ImportsSystem.Net

ImportsSystem.Net.NetworkInformation

PublicClassForm1

PrivateSubbtnGetMac_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesbtnGetMac.Click

DimNetworkInterfaces()AsNetworkInterface

NetworkInterfaces=NetworkInterface.GetAllNetworkInterfaces()

IfNetworkInterfaces.Length>0Then

txtMac.Text=txtMac.Text+

"MAC地址:"+NetWork.GetPhysicalAddress().ToString()+Environment.NewLine+

"網路連接:"+NetWork.Name+Environment.NewLine+

"網卡序列號:"+NetWork.Id+Environment.NewLine+

"網路類型:"+NetWork.NetworkInterfaceType.ToString()+Environment.NewLine+

"網路速度:"+(NetWork.Speed/1000000).ToString()+"MB"+Environment.NewLine

Next

EndIf

EndSub

EndClass

㈤ 如何用VB編程,獲取網關MAC

一、用nbtstat -a ip 命令,用.net中processstartinfo和process類取得命令輸出,最後一行就是mac地址 mac address.
二、用.net中的wmi:system.management namespace hosted in system.management.dll assembly
例:
managementobjectsearcher query = new managementobjectsearcher(

㈥ 如何用VB獲得機器的MAC地址

PrivateSubForm_Load()
GetMyIP
EndSub
SubGetMyIP()'獲取IP地址、網卡類型、網卡地址
DimstrComputerAsString
DimobjWMIAsObject
DimcolIPAsObject
DimIPAsObject
DimIAsInteger
strComputer="."
SetobjWMI=GetObject("winmgmts://"&strComputer&"/root/cimv2")
SetcolIP=objWMI.ExecQuery_
("Select*fromWin32_=TRUE")
ForEachIPIncolIP
IfNotIsNull(IP.IPAddress)Then
ForI=LBound(IP.IPAddress)ToUBound(IP.IPAddress)
MsgBox"IP地址:"&IP.IPAddress(I)&Chr(10)&_
"網卡類型:"&IP.Description(I)&Chr(10)&_
"網卡地址:"&IP.Macaddress(I)
Next
EndIf
Next
EndSub

㈦ 用vb.net如何取得mac地址

這是C#的,你可以轉換一下

using System.Management;

//獲取網卡的系列號
private static string GetMacAddress()
{
string ret = "";
try
{
ManagementClass cimobject = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection moc = cimobject.GetInstances();
if (moc.Count == 0)
return "";
else
{
foreach (ManagementObject mo in moc)
{
if ((bool)mo["IPEnabled"] == true)
{
ret = (string)mo.Properties["MacAddress"].Value;
break;
}
}
}
}
catch
{
ret = "";
}
return ret;
}

㈧ VB讀取MAC地址

樓主可以搜搜
網路文庫 源碼愛好者 等等網站

'Downlod by http://www.codefans.net
Option Explicit

Public CheckCode As Long

Private Const NCBASTAT As Long = &H33
Private Const NCBNAMSZ As Integer = 16
Private Const HEAP_ZERO_MEMORY As Long = &H8
Private Const HEAP_GENERATE_EXCEPTIONS As Long = &H4
Private Const NCBRESET As Long = &H32
Private Type NCB
ncb_command As Byte
ncb_retcode As Byte
ncb_lsn As Byte
ncb_num As Byte
ncb_buffer As Long
ncb_length As Integer
ncb_callname As String * NCBNAMSZ
ncb_name As String * NCBNAMSZ
ncb_rto As Byte
ncb_sto As Byte
ncb_post As Long
ncb_lana_num As Byte
ncb_cmd_cplt As Byte
ncb_reserve(9) As Byte
ncb_event As Long
End Type
Private Type ADAPTER_STATUS
adapter_address(5) As Byte
rev_major As Byte
reserved0 As Byte
adapter_type As Byte
rev_minor As Byte
ration As Integer
frmr_recv As Integer
frmr_xmit As Integer
iframe_recv_err As Integer
xmit_aborts As Integer
xmit_success As Long
recv_success As Long
iframe_xmit_err As Integer
recv_buff_unavail As Integer
t1_timeouts As Integer
ti_timeouts As Integer
Reserved1 As Long
free_ncbs As Integer
max_cfg_ncbs As Integer
max_ncbs As Integer
xmit_buf_unavail As Integer
max_dgram_size As Integer
pending_sess As Integer
max_cfg_sess As Integer
max_sess As Integer
max_sess_pkt_size As Integer
name_count As Integer
End Type
Private Type NAME_BUFFER
name As String * NCBNAMSZ
name_num As Integer
name_flags As Integer
End Type
Private Type ASTAT
adapt As ADAPTER_STATUS
NameBuff(30) As NAME_BUFFER
End Type
Private Declare Function Netbios Lib "netapi32.dll" (pncb As NCB) As Byte
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (hpvDest As Any, _
ByVal hpvSource As Long, _
ByVal cbCopy As Long)
Private Declare Function GetProcessHeap Lib "kernel32" () As Long
Private Declare Function HeapAlloc Lib "kernel32" (ByVal hHeap As Long, _
ByVal dwFlags As Long, _
ByVal dwBytes As Long) As Long
Private Declare Function HeapFree Lib "kernel32" (ByVal hHeap As Long, _
ByVal dwFlags As Long, _
lpMem As Any) As Long

Public Function GetMAC() As Integer

Dim bRet As Byte
Dim myNcb As NCB
Dim myASTAT As ASTAT
Dim pASTAT As Long
Dim intMAC As Integer

myNcb.ncb_command = NCBRESET
bRet = Netbios(myNcb)
With myNcb
.ncb_command = NCBASTAT
.ncb_lana_num = 0
.ncb_callname = "* "
.ncb_length = Len(myASTAT)
pASTAT = HeapAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS Or HEAP_ZERO_MEMORY, .ncb_length)
End With
If pASTAT = 0 Then
Exit Function
End If
myNcb.ncb_buffer = pASTAT
bRet = Netbios(myNcb)
CopyMemory myASTAT, myNcb.ncb_buffer, Len(myASTAT)
intMAC = myASTAT.adapt.adapter_address(0)
intMAC = intMAC + myASTAT.adapt.adapter_address(1)
intMAC = intMAC + myASTAT.adapt.adapter_address(2)
intMAC = intMAC + myASTAT.adapt.adapter_address(3)
intMAC = intMAC + myASTAT.adapt.adapter_address(4)
intMAC = intMAC + myASTAT.adapt.adapter_address(5)
GetMAC = intMAC
Call HeapFree(GetProcessHeap(), 0, pASTAT)

End Function

Public Function GetMACAddress() As String

Dim bRet As Byte
Dim myNcb As NCB
Dim myASTAT As ASTAT
Dim pASTAT As Long
myNcb.ncb_command = NCBRESET
bRet = Netbios(myNcb)
With myNcb
.ncb_command = NCBASTAT
.ncb_lana_num = 0
.ncb_callname = "* "
.ncb_length = Len(myASTAT)
pASTAT = HeapAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS Or HEAP_ZERO_MEMORY, .ncb_length)
End With
If pASTAT = 0 Then
Exit Function
End If
myNcb.ncb_buffer = pASTAT
bRet = Netbios(myNcb)
CopyMemory myASTAT, myNcb.ncb_buffer, Len(myASTAT)
GetMACAddress = HexEx(myASTAT.adapt.adapter_address(0)) & "-" & HexEx(myASTAT.adapt.adapter_address(1)) & "-" & HexEx(myASTAT.adapt.adapter_address(2)) & "-" & HexEx(myASTAT.adapt.adapter_address(3)) & "-" & HexEx(myASTAT.adapt.adapter_address(4)) & "-" & HexEx(myASTAT.adapt.adapter_address(5))
Call HeapFree(GetProcessHeap(), 0, pASTAT)

End Function

Private Function HexEx(ByVal B As Long) As String

Dim aa As String

aa = Hex$(B)
If Len(aa) < 2 Then
aa = "0" & aa
End If
HexEx = aa

End Function

閱讀全文

與vb編程怎麼找mac地址相關的資料

熱點內容
蘋果藍牙鍵盤surface 瀏覽:170
mindmaplinux 瀏覽:733
oppo手機怎麼連接電腦傳輸數據 瀏覽:624
word刪除章節附註分隔符 瀏覽:773
公告質疑需要哪些文件 瀏覽:608
資料庫模型是干什麼的 瀏覽:404
win10的驅動怎麼安裝驅動 瀏覽:320
word文件水印怎麼取消 瀏覽:443
rhel6的鏡像文件在哪裡下載 瀏覽:571
成功正能量微信頭像 瀏覽:848
wps表格如何恢復數據 瀏覽:264
linuxc靜態庫創建 瀏覽:838
u盤有微信文件但微信恢復不了 瀏覽:585
蘋果的網站數據是什麼 瀏覽:22
ps滾字教程 瀏覽:237
win7網路鄰居如何保存ftp 瀏覽:186
安卓客戶端代理伺服器 瀏覽:572
編程用蘋果 瀏覽:659
51虛擬機的文件管理在哪裡 瀏覽:13
win10系統有沒有便簽 瀏覽:722

友情鏈接