Jump to content

Capture MAC Address


Recommended Posts

Well I saw ChrisL's excellent WMI/Scripto example in another thread so I hacked together the following function from it. It's a cut-down function that returns the macs and their descriptions. Just posting for completness/an alternative method as I've seen Chris's example on page one of this thread - someone may find it useful.

Sorry I cant take credit for it, Scriptomatic was made by SvenP http://www.autoitscript.com/forum/index.ph...hl=scriptomatic I just used it to create the code and stripped a couple of bits out for what was required

Edited by ChrisL
Link to comment
Share on other sites

@kerrycorcoran,

Forgot to say - Welcome to the forum! So, welcome.

[Try not to be overwhelmed by all of the helpful posts and code.]

I think that MSL was pointing out something for you (and those posting scripts) to think about and I'll add: What if the MAC address has been changed via a NetworkAddress entry? What if it changes with every boot? or randomly thru out the day? The point is; you asked how to "capture the MAC address". You might not want to put too much stock in a MAC address these days. At least on the XP OS, it is easy to change.

My point is not about spoofing MAC addresses (which can be easily done through the device manager), but it instead about telling people who post code to think about multiple possibilities. If there is more than 1 NIC installed, than more than one MAC address will be listed, which can create a problem for some people. I personally have 3 NIC installed (2 wired, 1 usb) as well as IPv6 and VMWare virtual interfaces (making ipconfig a huge output :P).

Writing AutoIt scripts since

_DateAdd("d", -2, _NowCalcDate())
Link to comment
Share on other sites

This version only returns the MAC Address of the network connections that are "connected"

$oPc = "."
$oWMI = ObjGet("winmgmts:\\" & $oPc & "\root\cimv2")
$oCol = $oWMI.ExecQuery("Select * From Win32_NetworkAdapter ")


For $oItm In $oCol
    If $oItm.NetConnectionStatus = 2 Then
    $mac = $oItm.MACAddress
    $name = $oItm.Name
    EndIf
Next

MsgBox(0, "Results", "Active Network Connection Device - " & $name & @CRLF & _ 
                     "MAC Address - " & $mac)

We have enough youth. How about a fountain of SMART?

Link to comment
Share on other sites

SvenP has written a great WMI Scripting utility based on the Microsoft Scripting Guys' Scriptomatic tool that can generate AutoIt code to work with WMI (beta required) - WMI ScriptOMatic tool for AutoIt (Scriptomatic.au3).

You can query the Win32_NetworkAdapter class to retrieve all the MAC addresses, or filter it by looking at other values.

See the item item "Get Default Gateway using WMI" in my signature below to see how the tool can be used to use the info to create a small function.

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