在 C++ 中为当前计算机生成 GUID 的简单方法是什么?
我目前正在开发一款第一人称射击游戏。
我想知道是否有一种方法可以生成一个 GUID,该 GUID 对于同一台计算机始终返回相同的值,但在另一台计算机上会有所不同。
我需要做这一代来有效禁止麻烦的用户。
我希望它能够在 Microsoft Visual C++ 和 g++ 上运行。
I am currently developing a first-person-shooter.
I would like to know if there is a way to generate a GUID that will always return the same value for the same machine, but will be different on another machine.
I need to do this generation to effectively ban troublesome users.
I want it to work on both Microsoft Visual C++ and g++.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以使用 MAC 地址。
此处描述了一种实现方法。
You could use the MAC address.
A way to do it is described here.
HKEY_CLASSES_ROOT 中还有 TMID。不过仅限 Windows。
There's also the TMID in HKEY_CLASSES_ROOT. Windows only though.
我会支持对 MAC 地址的投票,因为每个 MAC 地址在制造时都是唯一的,但随后就会遇到欺骗问题。我建议您将其基于多个值,例如卷序列号、CPU 型号/步进、MAC 地址和磁盘制造商(仅作为示例)。这取决于您,但尽量避免仅依赖单个值,因为它总是可能会发生变化,但话又说回来,如果您的任何识别因素发生变化,GUID 也会发生变化,因此您需要在机器之间选择某种持久值。像产品密钥或产品 ID 之类的东西可能是更好的选择,但我不确定这是否很容易访问(如果有的话)。
I would second the vote on the MAC address, because every MAC address is unique when manufactured, but then you run the issue of spoofing. I recommend you base it on multiple values such as the volume serial number, CPU model/stepping, MAC Address, and the disk manufacturer just as an example. It's up to you, but try to avoid relying on just a single value as that could always change, but then again, the GUID would change if any of your identifying factors changed, so you would need to pick some kind of persistent value between machines. Something like the product key, or product id rather might be a better choice, but im not sure if thats easily accessible if at all.
您可以在
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography
注册表项中读取 MachineGuid 项。这适用于 Windows,但您需要针对其他操作系统的替代方法。
You could read the MachineGuid key at the
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography
registry key.That would work on Windows, but you'd need an alternate method for other OS's.