Jump to content
Sign in to follow this  
evilpacketmonkey

MAC Address.. [Solved]

Recommended Posts

evilpacketmonkey

^_^

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 by evilpacketmonkey

Share this post


Link to post
Share on other sites
Richard Robertson

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"

Share this post


Link to post
Share on other sites
SoulA

I found this here

if you know the ip of the adapter

$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

Share this post


Link to post
Share on other sites
evilpacketmonkey

I found this here

if you know the ip of the adapter

$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.

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.