导航:首页 > 电脑网站 > 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地址相关的资料

热点内容
把安卓软件变成苹果软件 浏览:6
电脑许可系统 浏览:573
电脑怎么加分 浏览:613
苹果电脑win7系统连接无线网 浏览:366
平板电脑插电脑 浏览:503
苹果下软件会多出来很多软件 浏览:984
旗舰版电脑在哪里连接数据线 浏览:910
戴尔电脑突然开机变得缓慢 浏览:251
台式电脑开机死机出现竖条纹 浏览:864
电脑b站看直播黑屏 浏览:94
截图电脑屏幕截图 浏览:374
电脑电源针脚哪个usb供电 浏览:963
电脑为什么会有辐射 浏览:168
砸掉平板电脑 浏览:854
八戒网电影免费网站 浏览:290
在线网站免费视频 浏览:80
电脑开机后一直刷数字 浏览:128
网吧电脑管理系统 浏览:935
联想a730平板电脑 浏览:633
现在手提电脑最低多少钱 浏览:886