How to get hardware MAC address on Windows
Asked Answered
P

3

14

I'm playing around with retrieving the MAC address from the NIC - there are a variety of ways to get it, this article covers the most common:

http://www.codeguru.com/Cpp/I-N/network/networkinformation/article.php/c5451

I'm currently using the GetAdaptersInfo method, which seems the most bulletproof, but if the MAC address has been set via the registry:

http://www.mydigitallife.info/2008/06/30/how-to-change-or-spoof-mac-address-in-windows-xp-vista-server-20032008-mac-os-x-unix-and-linux/

Then it reports the MAC address that it has been changed to. The only way I've found to actually get the true MAC is to remove the registry entry, restart the NIC, get the MAC via GetAdaptersInfo, then replace the registry entry, and restart the NIC. While it gets the job done, it's hardly transparent to the user.

Is there any other methods that anyone is familiar with, that will return the hardware MAC regardless of what the registry is set to? Ideally I'd like a solution that works on XP on up.

Thanks in advance!

Pains answered 5/5, 2009 at 6:7 Comment(0)
G
2

My guess is that in the linked CodeGuru article, the Miniport solution is likely to overcome the problem you describe, albeit painful to implement. The reason I think this is that I have used the GetAdaptersInfo solution myself in the past, and noticed that the MAC address will change without reboot when an adapter is added, e.g. a Bluetooth adapter providing PAN services.

Perhaps rather than rebooting after changing the registry setting, you could try stopping and restarting the relevent network services. You could easily check this manually prior to looking for a programmatic solution.

(n.b. the above is all guess work. If you try it and it works, perhaps add a post for those trying to do the same in future).

Got answered 5/5, 2009 at 8:6 Comment(2)
So it looks like the Miniport solution works, but has a high likelyhood of not being supported going forward. I found this link from the NDIS gurus over at PCUSA: pcausa.com/Utilities/macaddr2.htm If you modify their example to query OID_802_3_PERMANENT_ADDRESS instead of OID_802_3_CURRENT_ADDRESS, it returns the hardware address.Pains
@Pains - some when in the last 8 years, that link has gone stale. :(Kalvin
A
1

You can use WMI to enumerate the Win32_NetworkAdapter instances and look at the MACAddress property. The main issue with this technique is finding the appropriate adapter instance if you have multiple active adapters installed, e.g. on a laptop which also has a wireless connection.

Anyhow answered 18/6, 2014 at 5:6 Comment(0)
E
-1

Parse the output of ipconfig /all

Ephesus answered 5/5, 2009 at 8:52 Comment(1)
ipconfig /all (at least on Vista) only displayed the MAC address from the registry.Pains

© 2022 - 2024 — McMap. All rights reserved.