導航:首頁 > 電腦網站 > vb如何獲取電腦mac地址

vb如何獲取電腦mac地址

發布時間:2025-05-17 14:00:10

⑴ vb獲取自己的mac/ip和網關的mac/ip

Private Function EthernetAddress(LanaNumber As Long) As String

Dim udtNCB As NCB
Dim bytResponse As Byte
Dim udtASTAT As ASTAT
Dim udtTempASTAT As ASTAT
Dim lngASTAT As Long
Dim strOut As String
Dim x As Integer

udtNCB.ncb_command = NCBRESET
bytResponse = Netbios(udtNCB)
udtNCB.ncb_command = NCBASTAT
udtNCB.ncb_lana_num = LanaNumber
udtNCB.ncb_callname = "* "
udtNCB.ncb_length = Len(udtASTAT)
lngASTAT = HeapAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS Or HEAP_ZERO_MEMORY, udtNCB.ncb_length)

strOut = ""

If lngASTAT Then
udtNCB.ncb_buffer = lngASTAT
bytResponse = Netbios(udtNCB)
CopyMemory udtASTAT, udtNCB.ncb_buffer, Len(udtASTAT)

With udtASTAT.adapt

For x = 0 To 5
strOut = strOut & Right$("00" & Hex$(.adapter_address(x)), 2)
Next x

End With

HeapFree GetProcessHeap(), 0, lngASTAT
End If

EthernetAddress = strOut
End Function

Function LocalIPAddress() As String
Dim cbRequired As Long
Dim buff() As Byte
Dim Adapter As IP_ADAPTER_INFO
Dim AdapterStr As IP_ADDR_STRING
Dim ptr1 As Long
Dim sIPAddr As String
Dim found As Boolean
Call GetAdaptersInfo(ByVal 0&, cbRequired)

If cbRequired > 0 Then
ReDim buff(0 To cbRequired - 1) As Byte

If GetAdaptersInfo(buff(0), cbRequired) = ERROR_SUCCESS Then
'獲取存放在buff()中的數據的指針
ptr1 = VarPtr(buff(0))

Do While (ptr1 <> 0)
'將第一個網卡的數據轉換到IP_ADAPTER_INFO結構中
CopyMemory Adapter, ByVal ptr1, LenB(Adapter)

With Adapter
'IpAddress.IpAddr成員給出了DHCP的IP地址
sIPAddr = TrimNull(StrConv(.IpAddressList.IpAddress.IpAddr, vbUnicode))

If Len(sIPAddr) > 0 Then
found = True
Exit Do
End If

ptr1 = .dwNext
End With 'With Adapter

'不再有網卡時,ptr1的值為0
Loop 'Do While (ptr1 <> 0)

End If 'If GetAdaptersInfo
End If 'If cbRequired > 0

'返回結果字元串
LocalIPAddress = sIPAddr
End Function

Function TrimNull(item As String)
Dim pos As Integer
pos = InStr(item, Chr$(0))

If pos Then
TrimNull = Left$(item, pos - 1)
Else: TrimNull = item
End If

End Function

Private Sub Form_Load()
Text1 = "IP地址:" & LocalIPAddress
Text2 = "MAC地址:" & EthernetAddress(0)
End Sub

閱讀全文

與vb如何獲取電腦mac地址相關的資料

熱點內容
電腦怎麼轉換系統賬戶 瀏覽:701
看4k60幀視頻電腦配置 瀏覽:820
電腦主機的風扇多少v的 瀏覽:585
孩子用電腦耳機哪個牌子好 瀏覽:972
電腦能安裝兩種顯卡驅動 瀏覽:257
去除廣告的電腦軟體 瀏覽:792
電腦開機按f11怎麼刪除 瀏覽:750
電腦里有什麼計算機二級的軟體 瀏覽:612
昂達平板電腦白屏 瀏覽:707
電腦怎麼綁定無線網 瀏覽:19
最爛的電腦配置 瀏覽:514
電腦系統總是崩潰 瀏覽:536
電腦開機不顯示pxe為什麼還是進不了系統 瀏覽:294
電腦卡住然後黑屏了無信號 瀏覽:740
微信電腦版怎麼用啊 瀏覽:494
安卓數據傳到蘋果用什麼軟體好 瀏覽:600
筆記本電腦帶有獨立顯卡要多少錢 瀏覽:26
電腦連手機wifi密碼錯誤 瀏覽:186
mac電腦屏幕旋轉90黑屏 瀏覽:111
蘋果檢測睡眠軟體 瀏覽:149