Finding MAC Address
For a project i needed to get the MAC Address of a machine. A simple task you might think. However there are numerous ways to achieve this and of course each way has certain drawbacks. Hence i thought i'd put together an article to share the information i gathered. From this you should hopefully be able to select the best method for you, without having to go through multiple webpages on the net or coding up some test apps. I have put WinAPI keywords in square brackets, look these up in MSDN for further information.
1) The Command Line - There are many commands available to you (depending on OS type), eg:- ipconfig, netstat, arp, GetMAC. Then its just a case of parsing the result. Obviously its not the most attractive programming style and you have to check responses for all the different OS's incase of differences.
2) A Unique Identifier [UuidCreate] - A generated UUID can be linked back to the MAC Address, however this isnt the case for Windows 2k/XP (for security reasons), but you can get by this using [UuidCreateSequential]. Only pitful here is that you can only get MACAddress of one network card.
3) NetBios [NetBios] - A NetBios call can return the MAC Address for you. Trouble is you need NetBIOS installed, which now days can not always be guaranteed.
4) SNMP [SnmpExtensionQuery] - Another method, which i found at this website. Only problem i found is that the MAC Address is not returned if running under a user account
5) SDK API, Method 1 [GetAdaptersInfo] - Well this looks promising a standard api call to give you lots of info about network cards in your machine. Couple of problems i ran into though. 1) Does not work under NT and 2) Does not run under a user account.
6) SDK API, Method 2 [GetIfTable] - A bit more complicated than above, but it seems to do the job. This one does run on NT (SP4+)!
7) Things get a bit simpler with .NET by the way. MSDN ManagementClass("Win32_NetworkAdapterConfiguration").
Well i hope this helps in any way with you getting a MAC Address. Note there may be errors in the above, as i did this a while back and this is all from memory. If uou spot any error, or things change with new releases, please drop me an email at email@example.com so i can correct it.