本帖最后由 飞越星海 于 2011-9-9 10:49 编辑
本人现在正在学习中,对很多东西都是不懂,现在想写几个输出电脑物理地址的代码来也不行,只好向大家求助!!!也让我好参考参考!!!大家一起来学习,一起进步!!!谢谢!!!
最后结果,虽然不是自己写出来的,但总是学到了一些知识!!!$sip=@IPAddress1;获取本机ip
If $sip="0.0.0.0" Then $sip=@IPAddress2;获取本机ip
$MAC = _GetMAC($sip);通过IP获取地址
MsgBox(0,"IP2地址:"&$sip,"MAC3地址:"&$MAC)
Func _GetMAC($sIP)
Local $MAC, $MACSize, $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
10楼的方法:$objWMIService = objget("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
$colItems = $objWMIService.ExecQuery("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")
For $objItem in $colItems
If StringLeft($objItem.MACAddress,2) = 00 Then $mac = $objItem.MACAddress
Next
MsgBox(0,0,$mac)
用连接号代替冒号方法:MsgBox(0,"","你的mac地址: "&StringReplace($mac,":","-")) |