Jump to content

MAC Address.. [Solved]


Recommended Posts

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
Link to comment
Share on other sites

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.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...