Sign in to follow this  
Followers 0
zelles

Get Mac Address Efficiently

6 posts in this topic

#1 ·  Posted (edited)

I was trying to get the MAC address of the computer running the script and the most efficient way seams to be using this function. I found it somewhere, but it was broken and would not run at all, and after making some change I got it displaying the Mac address. Does anyone know a more efficient way? This seams pretty efficient. Also, even though it works without issue, did I do things right in the function?

Working function to get the MAC address:

$IP_Address = @IPAddress1

$MAC_Address = GET_MAC($IP_Address)

MsgBox(0, "MAC Address:", $MAC_Address)

Func GET_MAC($_MACsIP)
    Local $_MAC,$_MACSize
    Local $_MACi,$_MACs,$_MACr,$_MACiIP
    $_MAC = DllStructCreate("byte[6]")
    $_MACSize = DllStructCreate("int")
    DllStructSetData($_MACSize,1,6)
    $_MACr = DllCall ("Ws2_32.dll", "int", "inet_addr", "str", $_MACsIP)
    $_MACiIP = $_MACr[0]
    $_MACr = DllCall ("iphlpapi.dll", "int", "SendARP", "int", $_MACiIP, "int", 0, "ptr", DllStructGetPtr($_MAC), "ptr", DllStructGetPtr($_MACSize))
    $_MACs  = ""
    For $_MACi = 0 To 5
    If $_MACi Then $_MACs = $_MACs & ":"
        $_MACs = $_MACs & Hex(DllStructGetData($_MAC,1,$_MACi+1),2)
    Next
    DllClose($_MAC)
    DllClose($_MACSize)
    Return $_MACs
EndFunc
Edited by zelles
2 people like this

Share this post


Link to post
Share on other sites



This could prove to be very handy. Thanks for sharing.

Share this post


Link to post
Share on other sites

I used this function in a small tool, to get the MAC from IP and the vendor name from MAC. Tool is called Ip2Mac&Vendor and can be found on german AutoIt forum: http://autoit.de/index.php/Thread/45340-Offline-IP-zu-MAC-und-Hersteller-Konverter/

Download: http://autoit.de/index.php/Attachment/24512-IP2Mac-Vendor-7z/


Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Share this post


Link to post
Share on other sites

How to get conection's name?

 

Share this post


Link to post
Share on other sites

WMI

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  
Followers 0