導航:首頁 > 電腦網站 > 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地址相關的資料

熱點內容
筆記本電腦連不了網怎麼回事 瀏覽:514
電腦顯示屏滑鼠鍵盤全不亮但是主機已開機 瀏覽:44
那個網址下載的電腦系統好用 瀏覽:598
如何打開筆記本電腦無線功能 瀏覽:770
寬屏筆記本電腦 瀏覽:249
蘋果軟體一鍵清理緩存 瀏覽:610
為什麼電腦設置鍵沒了 瀏覽:295
蘋果5閱讀軟體 瀏覽:522
wifi出問題電腦連不上 瀏覽:662
電腦插上無線網卡怎麼連接不了 瀏覽:474
可以修復硬碟的電腦 瀏覽:674
電腦哪個桌面壁紙app好 瀏覽:864
服裝店的電腦多少錢 瀏覽:770
電腦卡住開機不能進入系統 瀏覽:7
cad對筆記本電腦的要求 瀏覽:432
剛買的筆記本電腦怎麼激活 瀏覽:811
wifi手機能連電腦不能 瀏覽:117
筆記本電腦咋充電 瀏覽:289
蘋果7都用什麼軟體 瀏覽:178
電腦桌面隱藏軟體 瀏覽:826