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

热点内容
电脑用无线连接怎么连 浏览:632
win10电脑显示器红绿蓝 浏览:605
大庆哪有卖平板电脑 浏览:416
怎么在苹果卸载软件 浏览:805
电脑安装系统为什么要分区 浏览:218
苹果手机美颜软件推荐 浏览:427
电脑开机9声报警怎么办 浏览:206
华为电脑操作系统国产 浏览:826
7000元组装电脑最强配置2021 浏览:863
红米笔记本电脑怎样修改开机密码 浏览:997
戴尔电脑重装系统步骤 浏览:357
为什么电脑网络红叉 浏览:303
电脑桌面作业帮在c盘哪个文件夹 浏览:107
联想笔记本电脑屏幕跳动不显示 浏览:364
组装电脑系统卡 浏览:233
为什么手机连接电脑上不了wifi 浏览:146
新手学炒股用哪款平板电脑好 浏览:960
电脑如何发送wifi 浏览:705
电脑屏幕光斑 浏览:461
电脑连接宽带最高能到多少 浏览:651