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

热点内容
一般哪里有修理电脑的 浏览:486
如何把电脑映射到外网 浏览:607
联想电脑查看硬盘使用时间 浏览:582
电脑系统的工具 浏览:697
低配置电脑游戏辅助 浏览:710
在电脑上随意涂画的软件 浏览:873
联想电脑按f9黑屏 浏览:148
都市类小说免费下载网站 浏览:338
电脑p明星图片软件哪个好 浏览:748
吃鸡联想电脑设置 浏览:9
重新安装驱动后电脑反应没了 浏览:568
标签机无线蓝牙电脑找不到 浏览:461
笔记本电脑怎么链接惠普打印机 浏览:415
win7电脑投电视怎么设置 浏览:239
低配电脑如何变触屏 浏览:823
穿越火线电脑配置一整套 浏览:218
怎么查找电脑里的视频文件在哪里设置 浏览:341
怎么调电脑的字体大小 浏览:475
电脑软件用英语表达 浏览:342
荣耀电脑连接wifi卡顿 浏览:760