简体   繁体   English

从UUID中提取MAC地址

[英]Extracting MAC addresses from UUIDs

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. 我工作的程序假定由Windows RPC API调用UuidCreateSequential()生成的UUID包含主以太网适配器的MAC地址。 Is this assumption correct or should I use a different method to get the MAC address? 这个假设是正确的还是我应该使用不同的方法来获取MAC地址?

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. 我不会依赖于此 - UuidCreateSequential拥有MAC地址的唯一原因是它试图保证UUID在整个网络中是唯一的。 Plus, why would you use such a weird way to get a MAC address? 另外,为什么你会用这种奇怪的方式来获取MAC地址? Use WMI and actually ask for the MAC address instead of a side-effect of a UUID creation function. 使用WMI并实际请求MAC地址而不是UUID创建功能的副作用。

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. MSDN上的文档明确说明这将包含计算机上以太网卡的地址。 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() . 如果您正在编写托管代码,我将使用NetworkInterface类并调用GetAllNetworkInterfaces() Or from C++ code, call GetAdaptersInfo , which is what the managed implementation uses. 或者从C ++代码中调用GetAdaptersInfo ,这是托管实现使用的。

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. 即使UuidCreateSequential工作,它也是一种非常模糊的方式来获取信息,并隐藏了具有多个适配器的计算机等潜在问题。

Only a version 1 UUID contains a MAC address, and only if the original generator had access to the MAC address to begin with. 只有版本1 UUID包含MAC地址,并且仅当原始生成器可以访问MAC地址时才开始。 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. 如果原始生成器无法访问MAC地址,则根据RFC 4122的4.5节,它将使用来自加密安全随机数生成器的6个随机字节。因此,无法保证MAC地址在UUID中给出的实际上是MAC地址。

In most cases, the only reason anyone would ever need to parse out the MAC address from a UUID is for forensic purposes. 在大多数情况下,任何人需要从UUID解析MAC地址的唯一原因是用于取证目的。 See for example the UUIDs embedded in the Word document payload for the Melissa virus. 例如,参见Melissa病毒的Word文档有效负载中嵌入的UUID。 Investigators extracted the MAC address from these IDs and matched it to the MAC address of the suspect's primary network adapter. 调查员从这些ID中提取MAC地址,并将其与嫌疑人主网络适配器的MAC地址相匹配。

If you are trying to obtain the MAC address of your own computer, there are far better ways of going about this. 如果您正在尝试获取自己计算机的MAC地址,那么有更好的方法可以解决这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM