来个传送门,忘记在哪看到的了。转帖一下,先谢谢原作者!
可参考$sIP = InputBox("MAC地址获取", "请输入IP地址", @IPAddress1, "", 150, 100, 500, 300)
$errIP = StringRegExp($sIP, "(((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?))", 3)
If @error <> 0 Then
MsgBox(0, "错误!", '请输入IP地址的正确格式',5)
Else
$MAC = _GetMAC($sIP)
If $MAC <> "000000000000" Then
ClipPut($MAC)
MsgBox(0, $MAC ," MAC已经复制在粘贴板!", 2)
Else
MsgBox(0, "MAC地址", '无法获取:"' & $sIP & '" 的MAC地址')
EndIf
EndIf
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 ;==>_GetMAC
|