获得mac地址的
$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
|