evilpacketmonkey Posted April 19, 2009 Posted April 19, 2009 (edited) I am unable to find the shortest method to get the mac address for the active adapter. Much like @IPAddress1 get's the IP address for the first adapter, I would like something like @MacAddress1. Thanks in advance. Edited April 19, 2009 by evilpacketmonkey
Richard Robertson Posted April 19, 2009 Posted April 19, 2009 If you want something simple, you can read the output from the ipconfig program. A better solution is to use WMI to read it. I used to know what you needed to access the network adapters but I don't remember now. You can search the forum for "WMI network adapter"
SoulA Posted April 19, 2009 Posted April 19, 2009 I found this hereif you know the ip of the adapterexpandcollapse popup$MAC = _GetMACFromIP (@IPAddress1) MsgBox (0, "MAC Value", $MAC) Func _GetMACFromIP ($sIP) Local $MAC,$MACSize Local $i,$s,$r,$iIP ;Create the struct ;{ ; char data[6]; ;}MAC $MAC = DllStructCreate("byte[6]") ;Create a pointer to an int ; int *MACSize; $MACSize = DllStructCreate("int") ;*MACSize = 6; DllStructSetData($MACSize,1,6) ;call inet_addr($sIP) $r = DllCall ("Ws2_32.dll", "int", "inet_addr", _ "str", $sIP) $iIP = $r[0] ;Make the DllCall $r = DllCall ("iphlpapi.dll", "int", "SendARP", _ "int", $iIP, _ "int", 0, _ "ptr", DllStructGetPtr($MAC), _ "ptr", DllStructGetPtr($MACSize)) ;Format the MAC address into user readble format: 00:00:00:00:00:00 $s = "" For $i = 0 To 5 If $i Then $s = $s & ":" $s = $s & Hex(DllStructGetData($MAC,1,$i+1),2) Next ;Return the user readble MAC address Return $s EndFunc
evilpacketmonkey Posted April 19, 2009 Author Posted April 19, 2009 I found this here if you know the ip of the adapter expandcollapse popup$MAC = _GetMACFromIP (@IPAddress1) MsgBox (0, "MAC Value", $MAC) Func _GetMACFromIP ($sIP) Local $MAC,$MACSize Local $i,$s,$r,$iIP ;Create the struct ;{ ; char data[6]; ;}MAC $MAC = DllStructCreate("byte[6]") ;Create a pointer to an int ; int *MACSize; $MACSize = DllStructCreate("int") ;*MACSize = 6; DllStructSetData($MACSize,1,6) ;call inet_addr($sIP) $r = DllCall ("Ws2_32.dll", "int", "inet_addr", _ "str", $sIP) $iIP = $r[0] ;Make the DllCall $r = DllCall ("iphlpapi.dll", "int", "SendARP", _ "int", $iIP, _ "int", 0, _ "ptr", DllStructGetPtr($MAC), _ "ptr", DllStructGetPtr($MACSize)) ;Format the MAC address into user readble format: 00:00:00:00:00:00 $s = "" For $i = 0 To 5 If $i Then $s = $s & ":" $s = $s & Hex(DllStructGetData($MAC,1,$i+1),2) Next ;Return the user readble MAC address Return $s EndFunc That did it. Thanks for the help! I honestly did try searching but I admittedly don't have very good search skills.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now