sprinkle 发表于 2008-9-27 00:37:36

如何获取网卡的MAC地址?

向各位高手求教

sanhen 发表于 2008-9-27 08:16:28

学会搜索。。。

zw2725 发表于 2009-6-28 21:48:56

$sIP = InputBox("MAC地址获取", "请输入IP地址", @IPAddress1, "", 150, 100, -1, -1)
$MAC = _GetMAC ($sIP)
If $MAC <> "00:00:00:00:00:00" Then
MsgBox (0, "MAC地址", '"' &$sIP& '" 的MAC地址是:'&$MAC)
Else
MsgBox (0, "MAC地址", '无法获取:"' &$sIP& '" 的MAC地址')
EndIf

Func _GetMAC ($sIP)
Local $MAC,$MACSize
Local $i,$s,$r,$iIP

$MAC = DllStructCreate("byte")
$MACSize = DllStructCreate("int")

DllStructSetData($MACSize,1,6)
$r = DllCall ("Ws2_32.dll", "int", "inet_addr", "str", $sIP)
$iIP = $r
$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

liyi-softs 发表于 2010-3-9 17:55:25

这个好啊....

gaozhenghong 发表于 2010-3-26 11:50:44

:face (1):支持

gaozhenghong 发表于 2010-3-26 11:51:11

可是为什么要先输入IP

308513523 发表于 2012-6-7 10:12:33

{:face (319):} 同求

6678720 发表于 2014-1-22 18:22:41

回复 3# zw2725


    这个很强,赞一个,实用!

au3x 发表于 2014-3-22 22:38:21

嗯,问得好呢! 为什么要输入IP?

haijie1223 发表于 2014-3-22 22:51:19

Dim $MAC, $MACSize, $i, $sIP, $aR

$MAC = DllStructCreate("byte")
$MACSize = DllStructCreate("int")
DllStructSetData($MACSize, 1, 6)
$aR = DllCall("Ws2_32.dll", "int", "inet_addr", "str", @IPAddress1)
$aR = DllCall("iphlpapi.dll", "int", "SendARP", "int", $aR1, "int", 0, "ptr", DllStructGetPtr($MAC), "ptr", DllStructGetPtr($MACSize))
$sIP = ""
For $i = 0 To 5
        If $i Then $sIP = $sIP & ":"
        $sIP = $sIP & Hex(DllStructGetData($MAC, 1, $i + 1), 2)
Next
MsgBox(0, "MAC地址查看器", "mac地址为:" & $s)

ak47gglllk 发表于 2014-6-29 10:43:05

感谢,感谢,感谢,感谢,好东西呀

cgfather 发表于 2014-8-8 22:43:55

谢谢楼主分享

au3x 发表于 2014-8-22 10:08:35

回复 10# haijie1223


    E:\au\ip\mac.au3(7,63) : WARNING: $aR1: 使用前并未进行声明.
$aR = DllCall("iphlpapi.dll", "int", "SendARP", "int", $aR1,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
E:\au\ip\mac.au3(13,45) : WARNING: $s: 使用前并未进行声明.
MsgBox(0, "MAC地址查看器", "mac地址为:" & $s)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
E:\au\ip\mac.au3(7,63) : 错误: $aR1: 未声明的全局变量.
$aR = DllCall("iphlpapi.dll", "int", "SendARP", "int", $aR1,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
E:\au\ip\mac.au3(13,45) : 错误: $s: 未声明的全局变量.
MsgBox(0, "MAC地址查看器", "mac地址为:" & $s)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
E:\au\ip\mac.au3 - 2 错误, 2 警告

haijie1223 发表于 2014-8-22 17:55:17

回复 13# au3x


    手误,自己改改就行了呗~Dim $MAC, $MACSize, $i, $sIP, $aR, $aR1

$MAC = DllStructCreate("byte")
$MACSize = DllStructCreate("int")
DllStructSetData($MACSize, 1, 6)
$aR1 = DllCall("Ws2_32.dll", "int", "inet_addr", "str", @IPAddress1)
$aR = DllCall("iphlpapi.dll", "int", "SendARP", "int", $aR1, "int", 0, "ptr", DllStructGetPtr($MAC), "ptr", DllStructGetPtr($MACSize))
$sIP = ""
For $i = 0 To 5
        If $i Then $sIP = $sIP & ":"
        $sIP = $sIP & Hex(DllStructGetData($MAC, 1, $i + 1), 2)
Next
MsgBox(0, "MAC地址查看器", "mac地址为:" & $sIP)

ticket 发表于 2015-8-17 00:18:24

谢谢了喔,正要需要用到
页: [1]
查看完整版本: 如何获取网卡的MAC地址?