Opinions

How to Programatically Get MAC Address of Physical Network Card?

This post is a bit off topic, in the sense that it is related to a problem that I am facing in programming.

A little background. When I started SYCODE, our software licensing mechanism used the hard disk serial number as a unique identifier of a computer and tied the product license to it. That became a problem because the serial number is really not a fixed thing. It changes every time you format a hard disk. And every time a customer formatted or changed his hard disk the serial number changed and our product stopped working. So we changed our licensing mechanism to use the MAC (Media Access Control) address of the network card on the computer as a unique identifier. A MAC address is a much better option because it cannot be changed and people don’t change network cards as often as they change or format hard disks.

However, off late, we have been facing issues with the MAC address as well. Here is the thing. We are using the GetAdaptersInfo function to get the MAC addresses of the network cards on the computer. The problem is that the IP_ADAPTER_INFO structure used by this function does not tell the programmer whether the MAC address belongs to an actual physical network card (something which you plug your network cable into) or a virtual network interface created by things like a VPN or WiFi connection. The problem with the MAC addresses of these virtual devices is that they are anything but constant. You get a new one every time you log on. So now we have customers coming to us asking for keys for new MAC addresses every time they restart their computer or network connection.

I have searched the internet far and wide to find a solution to this problem and have come up with nothing. Basically I am looking for C/C++ code (not .NET) to get the MAC address of the primary physical network card on a computer. Someone suggested to pick the MAC address with the fastest speed. I don’t think that is a wise idea.

I am not sure how many programmers read this blog. If any of you have any idea or could point me to some place where I might find a solution, I would greatly appreciate it.

Update

I just found out that Windows stores the description of the physical network cards in the registry at HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindows NTCurrentVersionNetworkCards. The same description is also listed in the “Description” member of the IP_ADAPTER_INFO structure. So I guess I can check whether this value figures in the registry to determine whether the MAC address belongs to a physical network card or not. What do you think?