tags:

views:

655

answers:

4

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?

+2  A: 

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.

JaredPar
Yet again, -1 for a completely valid answer. At least have the guts to post a reason in the comment section
JaredPar
+3  A: 

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.

Paul Betts
???. The documentation says the function was specifically created to get the MAC address.
JaredPar
JaredPar: No, the documentation says that the function was created to *use* the MAC address. All that the documentation says is that the UUID returned is unique for that MAC address, it does not mean that the MAC address is recoverable from the UUID.
DavidK
Yup - the first two MAC bits are not useful in generating GUIDs.
MSalters
+1  A: 

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.

Charlie
A: 

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.

Bob Aman