请问如果网络还没有连通怎样可以获取本机的MAC?
lixiang 发表于 2009-5-16 17:32
老兄,别到处开贴,你前面那个帖子不是有人给出解决方法了嘛
http://www.autoitx.com/forum.php?mod=viewthread&tid=6554&extra=page%3D1
$sip=@IPAddress1;获取本机ip
If $sip="0.0.0.0" Then $sip=@IPAddress2;获取本机ip
If $sip="0.0.0.0" Then $sip=@IPAddress3
If $sip="0.0.0.0" Then $sip=@IPAddress4
If $sip="0.0.0.0" Then MsgBox(0,"IP怎么是 0.0.0.0 ?","貌似没有发现网卡,难道我脑子出问题了?")
$MAC = _GetMAC($sip);通过IP获取地址
MsgBox(0,"IP地址:"&$sip,"MAC地址:"&$MAC)
Func _GetMAC($sIP)
Local $MAC, $MACSize
Local $i, $s, $r, $iIP
$MAC = DllStructCreate("byte[6]")
$MACSize = DllStructCreate("int")
DllStructSetData($MACSize, 1, 6)
$r = DllCall("Ws2_32.dll", "int", "inet_addr", "str", $sIP)
$iIP = $r[0]
$r = DllCall("iphlpapi.dll", "int", "SendARP", "int", $iIP, "int", 0, "ptr", DllStructGetPtr($MAC), "ptr", DllStructGetPtr($MACSize))
$s = ""
For $i = 0 To 5
If $i Then $s = $s & "-"
$s = $s & Hex(DllStructGetData($MAC, 1, $i + 1), 2)
Next
Return $s
EndFunc
验证过,即使无网络也可顺利获取mac地址 |