如何用C语言唯一标识一台机器?
我想在 C 语言中唯一标识一台机器。
以下是具有序列号的源,但不能保证它们是唯一的或存在的(如可移动 HDD 或网卡)。
- CPU:我正在使用
cpuid
指令,但是,除Pentium 3之外的任何处理器都没有实现序列号,即不相关。我可以使用处理器签名,但这对于每个处理器来说并不是唯一的。 - 硬盘:?
- BIOS:?
- 母板: ?
- MAC地址:通过系统函数调用。
对于所有的问号,我如何获得 C 语言中的序列号? 如果您回答与系统相关的解决方案,请提供 Windows/*nix。 另外,对于 Windows,请不要使用 WMI。
谢谢!
I want to uniquely identify a machine in C.
The following are sources which have serial numbers, but they aren't guaranteed to be unique, or present (like a removable HDD or network card).
- CPU: I'm using the
cpuid
instruction, however, serial number is not implemented for any processor except Pentium 3, i.e. not relevant. I can use the processor signature, but this won't be unique for every processor. - HDD: ?
- BIOS: ?
- motherboard: ?
- MAC address: via system function calls.
For all the question marks, how would I get the serial numbers in C?
If you answer with a system dependent solution, please provide both Windows/*nix.
Also, for Windows, please no WMI.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一般来说,您需要识别组件的组合,并了解组件可以并且将会随着时间的推移而变化。您需要容差算法来做出明智的猜测,以了解更改何时代表您之前识别的机器的更新或您以前未见过的新机器。
一种简单的方法是,当您需要确定正在处理的机器并与您之前见过的机器的快照进行比较时,枚举您列出的所有组件。如果任何序列号匹配,您可以非常安全地假设您正在处理同一台机器(尽管当然有可能有人将硬盘驱动器转移到新机器......但是,这就是简单的商业级启发式方法要复杂得多。)。
使用这种专门用于软件激活的方法受到积极执行的专利的保护,因此请小心您所做的事情。如果您确实想这样做来保护您的软件,那么最好使用商业解决方案。有些是相当实惠的。谷歌“软件激活”选项。
这里有一些获取特定系统信息的参考(并非所有都是特定的 C 食谱,但每种情况都可以使用 C)。
硬盘窗口
http://www.codeproject.com/KB/cs/hard_disk_serialno.aspx
硬盘Linux
http://www.webmasterworld.com/forum40/957.htm
BIOS Windows
http://msdn.microsoft.com/en -us/library/aa394077(v=vs.85).aspx
BIOS Linux
http://www .dufault.info/blog/a-better-way-to-find-your-bios-version-in-linux/
Windows MAC 地址
C++:获取 Vista 上网络适配器的 MAC 地址?
MAC地址Linux
http://www.linuxquestions .org/questions/programming-9/linux-确定-mac-address-from-c-38217/
Generally speaking, you need to identify a combination of components and understand that components can and will change over time. You need tolerance algorithms to make an informed guess about when a change represents an update to a machine you previously identified, or a new machine you have not seen before.
A simple approach would be to enumerate all of the components you listed when you need to determine which machine you're dealing with and compare to previous snapshots of machines you have previously seen. If anything with a serial number matches, you can pretty safely assume you're dealing with the same machine (though of course it's possible that someone transferred a hard drive to a new machine... but then, this is the simple approach. Commercial grade heuristics are much more complicated.).
Use of this approach specifically for software activation is covered by a patent that is actively enforced, so be careful about what you're doing. If you do want to do this to protect your software, it may be better to use a commercial solution. Some are quite affordable. Google "software activation" for options.
Here are some references for obtaining the specific system information (not all are specific C cookbooks, but C can be used in each case).
HDD Windows
http://www.codeproject.com/KB/cs/hard_disk_serialno.aspx
HDD Linux
http://www.webmasterworld.com/forum40/957.htm
BIOS Windows
http://msdn.microsoft.com/en-us/library/aa394077(v=vs.85).aspx
BIOS Linux
http://www.dufault.info/blog/a-better-way-to-find-your-bios-version-in-linux/
MAC Address Windows
C++: Get MAC address of network adapters on Vista?
MAC Address Linux
http://www.linuxquestions.org/questions/programming-9/linux-determining-mac-address-from-c-38217/