Question

A program that I work on assumes that the UUID generated by the Windows RPC API call UuidCreateSequential() contains the MAC address of the primary ethernet adapter. Is this assumption correct or should I use a different method to get the MAC address?

Was it helpful?

Solution

I wouldn't rely on this - the only reason that UuidCreateSequential has the MAC address is it's trying to guarantee that the UUID is unique across the network. Plus, why would you use such a weird way to get a MAC address? Use WMI and actually ask for the MAC address instead of a side-effect of a UUID creation function.

OTHER TIPS

This appears to be a valid assumption. The documentation on MSDN specifically says this will contain the address of the ethernet card on the machine. It doesn't mention anything about a mult-card scenario but picking the primary card appears to be a logical leap.

If you're writing managed code, I would use the NetworkInterface class and call GetAllNetworkInterfaces(). Or from C++ code, call GetAdaptersInfo, which is what the managed implementation uses.

Even if UuidCreateSequential does work for this, it's a pretty obscure way to get the info, and hides potential issues like a computer having more than one adapter.

Only a version 1 UUID contains a MAC address, and only if the original generator had access to the MAC address to begin with. If the original generator didn't have access to a MAC address, it would have used 6 random bytes sourced from a cryptographically secure random number generator, as per section 4.5 of RFC 4122. Because of this, there is no guarantee that the MAC address given in a UUID is actually a MAC address.

In most cases, the only reason anyone would ever need to parse out the MAC address from a UUID is for forensic purposes. See for example the UUIDs embedded in the Word document payload for the Melissa virus. Investigators extracted the MAC address from these IDs and matched it to the MAC address of the suspect's primary network adapter.

If you are trying to obtain the MAC address of your own computer, there are far better ways of going about this.

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