Question

My platform is Windows 7 (or later), and I am using Visual Studio 2010.

In an attempt to get a unique machine identifier, I was trying to retrieve the mac address and I encountered the following problem.

I am having difficulty identifying which is the primary ethernet network adapter from the list of adapters returned by GetAdapatersInfo method.

I can get a list of ethernet adapters by checking their type (it should be MIB_IF_TYPE_ETHERNET).

However, there are multiple ethernet adapters on my machine: Actual LAN adapter, Cisco created software adapter, bluetooth ethernet adapater, etc.

Depending upon how I am connected to the internet, this list keeps changing.

So, how do I know which one is the actual ethernet adapter (the one that will connect using LAN cable).

Was it helpful?

Solution

Well,

After experimenting for some time (about one month), the volume number seems to be a reliable metric for generating unique id which is persistent across reboots and which cannot be changed by the user. This id will not change unless the disk is reformatted.

The following code fetches the volume number.

int getVolumeNumber(char *volumeNumber, int capacity) {
for(int i=0; i<capacity; i++) {
    volumeNumber[i] = '\0';
}
TCHAR volumeName[MAX_PATH + 1] = { 0 };
TCHAR fileSystemName[MAX_PATH + 1] = { 0 };
DWORD serialNumber = 0;
DWORD maxComponentLen = 0;
DWORD fileSystemFlags = 0;
if(GetVolumeInformation(_T("C:\\"), volumeName, ARRAYSIZE(volumeName), &serialNumber, &maxComponentLen, &fileSystemFlags, fileSystemName, ARRAYSIZE(fileSystemName)) != 0) {
    sprintf(volumeNumber,"%lu",serialNumber);
    return 0;
} else {
    return 1;
}

}

In the above code, I am fetching the volume number of the C: drive.

OTHER TIPS

"the volume number seems to be a reliable metric for generating unique id which is persistent across reboots and which cannot be changed by the user."

The last part of this statement ("cannot be changed by the user.") is not true. There are several utilities which either change or spoof the volume serial number. See for example https://www.raymond.cc/blog/changing-or-spoofing-hard-disk-hardware-serial-number-and-volume-id/ . Depending on your use case, you might be slightly better off using the hard disk serial number, which is provided by the HD manufacturer and cannot be changed by the user (but CAN be spoofed). It can be retrieved using the Win32_PhysicalMedia class (https://msdn.microsoft.com/en-us/library/windows/desktop/aa394346%28v=vs.85%29.aspx).

Another option might be to enumerate all ethernet adapters, sort them and compare the result - but it seems you have investigated this road.

In general, anything that could be used as a unique ID of a PC could be used for "software protection" (i.e. preventing unauthorised use of software), and it is therefore highly probable that people have tried to find ways to circumvent it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top