windows 生成基于硬件的computerID
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6131123/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Generating hardware based computerID
提问by Philip Bennefall
I had a question regarding generating a specific computer ID for licensing purposes. Preferably this ID should be hardware based, and thus should not change if the user reformats for example. Also it should not be easy (or preferably even impossible) for the user to change the information that the ID is generated from. Currently I only have two components that I combine, the CPUID standard and feature flags and the geometry and total size of the first physical drive in the machine. While this seems to be good for most general PC's, a lot of netbooks for example are made with the exact same hardware and so you would get the same ID for many machines in that case. Can any of you suggest some other hardware component I could use?
我有一个关于为许可目的生成特定计算机 ID 的问题。最好这个 ID 应该是基于硬件的,因此如果用户重新格式化,则不应更改。此外,用户更改生成 ID 的信息不应该是容易的(或者最好是不可能的)。目前我只有两个组件可以组合,CPUID 标准和功能标志以及机器中第一个物理驱动器的几何形状和总大小。虽然这对于大多数普通 PC 来说似乎很好,但例如很多上网本都是用完全相同的硬件制造的,因此在这种情况下,您会为许多机器获得相同的 ID。你们中的任何人都可以推荐一些我可以使用的其他硬件组件吗?
I have two requirements:
我有两个要求:
It must not use WMI.
It must work in a large number of situations (including for users with no or few privileges). I thought of using the serial of the physical drive, but that seems hard to retrieve if the user is not in administrator mode.
它不能使用 WMI。
它必须在大量情况下工作(包括没有或只有很少权限的用户)。我想过使用物理驱动器的序列号,但如果用户不在管理员模式下,这似乎很难检索。
I am working in C++ on Windows.
我在 Windows 上使用 C++。
Thanks in advance for any suggestions.
在此先感谢您的任何建议。
采纳答案by ravenspoint
You can use the first MAC address, which is assigned by the manufacturer of the hardware and will never change.
您可以使用第一个 MAC 地址,该地址由硬件制造商分配并且永远不会更改。
Something like this:
像这样的东西:
/**
return string containing first MAC address on computer
requires adding Iphlpapi.lib to project
*/
string GetMac()
{
char data[4096];
ZeroMemory( data, 4096 );
unsigned long len = 4000;
PIP_ADAPTER_INFO pinfo = ( PIP_ADAPTER_INFO ) data;
char sbuf[20];
string sret;
DWORD ret = GetAdaptersInfo( pinfo, &len );
if( ret != ERROR_SUCCESS )
return string("**ERROR**");
for(int k = 0; k < 5; k++ ) {
sprintf(sbuf,"%02X-",pinfo->Address[k]);
sret += sbuf;
}
sprintf(sbuf,"%02X",pinfo->Address[5]);
sret += sbuf;
return( sret );
}
IMHO, this is sufficient for licensing software valued up to a thousand dollars, where all that is necessary is to prevent casual consumers from sharing your software with their neighbours. A motivated pirate can get around it, but pirates with sufficient knowledge and motivation are not frequent enough to make it worthwhile for you to spend any more effort trying to defeat them and, even more important, you do not want to inconvenience your honest clients.
恕我直言,这对于价值高达 1000 美元的软件许可来说已经足够了,其中所需要的只是防止临时消费者与邻居共享您的软件。有上进心的海盗可以绕过它,但拥有足够知识和动机的海盗的频率不足以让您花更多的精力来击败他们,更重要的是,您不想给诚实的客户带来不便。
If your software is so valuable that motivated pirates are a real threat, then the cost and inconvenience of a hardware dongle becomes justified.
如果您的软件非常有价值,以至于有动机的盗版者成为真正的威胁,那么硬件加密狗的成本和不便就变得合理了。
Neither do I believe in piling on more hardware signatures, disk drive IDs, motherboard configurations and so on. The increase in security is minimal and the chance that something may go wrong increases greatly so that you will end up wasting hours supporting clients with unusual setups and pissing off unknown numbers who simply give up on you.
我也不相信堆积更多的硬件签名、磁盘驱动器 ID、主板配置等等。安全性的提高是最小的,并且出现问题的可能性大大增加,因此您最终将浪费时间支持具有不寻常设置的客户,并激怒那些只是放弃您的未知号码。
Implement a simple system with the MAC address, which always seems to work. Accept that an occasional pirate may get their kicks from breaking your licence. Focus your efforts on improving your software so that you will gain more honest clients.
使用 MAC 地址实现一个简单的系统,它似乎总是有效。接受偶尔的海盗可能会因违反您的许可证而受到打击。集中精力改进您的软件,以便您获得更多诚实的客户。
A system may have more than one network card ( e.g. ethernet and wireless ) and it is possible for the user to change the presentation order ( why would a user do this? ). To handle this, a licence would need to match a network card present anywhere on the system, requiring code something like this:
一个系统可能有多个网卡(例如以太网和无线网卡),用户可以更改显示顺序(用户为什么要这样做?)。为了解决这个问题,许可证需要匹配系统上任何地方存在的网卡,需要这样的代码:
/**
The MAC addresses of ethernet network cards present on computer
@param[out] vMAC vector of strings containing MAC addresses in XX-XX-XX-XX-XX-XX format
returns empty vector on error
See discussion of this
http://stackoverflow.com/questions/6131123/generating-hardware-based-computerid/6131231#6131231
*/
void cLicenser::GetMac( vector < string >& vMac )
{
vMac.clear();
char data[4096];
ZeroMemory( data, 4096 );
unsigned long len = 4000;
PIP_ADAPTER_INFO pinfo = ( PIP_ADAPTER_INFO ) data;
DWORD ret = GetAdaptersInfo( pinfo, &len );
if( ret != ERROR_SUCCESS )
return;
while ( pinfo )
{
// ignore software loopbacks
if( pinfo->Type != MIB_IF_TYPE_LOOPBACK )
{
char sbuf[20];
string sret;
for(int k = 0; k < 5; k++ )
{
sprintf(sbuf,"%02X-",pinfo->Address[k]);
sret += sbuf;
}
sprintf(sbuf,"%02X",pinfo->Address[5]);
sret += sbuf;
vMac.push_back( sret );
}
pinfo = pinfo->Next;
}
}
回答by user258808
I tried doing something similar a few years ago and failed. I tried using a combination of hardware ID's that I could read. Most CPU's have a CPUID, a unique number that is used to uniquely identify and track them. However the problem is that its not garunteed that each CPU out there will have this ID. In fact, when I tried it the Intel Celeron series did not have this ID. Certain Motherboards(mainly Intel) also shipped with a unique ID that you can use.
几年前我尝试做类似的事情但失败了。我尝试使用我可以读取的硬件 ID 的组合。大多数 CPU 都有一个 CPUID,这是一个用于唯一标识和跟踪它们的唯一编号。然而,问题是它并不能保证每个 CPU 都有这个 ID。其实我试的时候Intel Celeron系列是没有这个ID的。某些主板(主要是 Intel)还附带一个您可以使用的唯一 ID。
Hereis a link to an article that describes how to get this information.
这是一篇文章的链接,该文章描述了如何获取此信息。
I also used any / all MAC ID's in combination with the CPU ID & MB ID as a seed to generate unique GUID. The more hardware ID's you use as seed the better this performed.The problem is that if you do upgrade any of the hardware components the ID changes and the software Key gets invalidated.
我还将任何/所有 MAC ID 与 CPU ID 和 MB ID 结合使用作为生成唯一 GUID 的种子。用作种子的硬件 ID 越多,性能就越好。问题是,如果您升级任何硬件组件,ID 会发生变化并且软件密钥会失效。
Also keep in mind that Virtual Machines complicate this even further. I think your best bet would be to do what Microsoft does.
还要记住,虚拟机使这进一步复杂化。我认为你最好的选择是做微软所做的。
Microsoft does use a similar approach where they take a Hardware fingerprint of a machine on which the OS is installed and communicate it along with the Registration Key to activate a copy of the OS / Office suite. If you upgrade your hardware significantly(I think 4 hardware components) the Key will change and you will have to contact Microsoft and provide proof to re-validate your copy of Windows.
微软确实使用了一种类似的方法,他们获取安装了操作系统的机器的硬件指纹,并将其与注册密钥进行通信以激活操作系统/办公套件的副本。如果您显着升级您的硬件(我认为是 4 个硬件组件),则密钥将发生变化,您必须联系 Microsoft 并提供证据以重新验证您的 Windows 副本。
回答by Daniel Williams
If you only need to generate it once, the a GUID will be unique to the machine that created it. The problem is you'll get a different value every time you generate one. But if it's a one-off per machine, a GUID will work.
如果您只需要生成一次,则 GUID 对创建它的机器来说将是唯一的。问题是每次生成一个值时都会得到不同的值。但是,如果每台机器一次性使用,则 GUID 将起作用。
If it needs to be the same per machine and generated multiple times, the the MAC address is the universal ID for machines (though you may have multiple MACs to choose from).
如果它需要每台机器相同并多次生成,则 MAC 地址是机器的通用 ID(尽管您可能有多个 MAC 可供选择)。
回答by Pete Wilson
If such a thing were easy and reliable, Microsoft would have found and patented it long ago.
如果这样的东西既简单又可靠,微软早就发现并申请了专利。
There have been attempts to protect software by some hardware doo-dad, including shipping a thing called a 'dongle' with every licensed software package. Hey Valuable New Customer! Just plug in the dongle and run your new software!
一些硬件老大曾试图保护软件,包括随每个许可软件包一起运送一种称为“加密狗”的东西。嘿,尊贵的新客户!只需插入加密狗并运行您的新软件!
It was a riot to see a Rube Goldberg arrangement of three or four dongles plugged one into the next and hanging off the parallel port, each enabling its own software package.
看到 Rube Goldberg 安排的三四个加密狗将一个插入下一个并挂在并行端口上,每个都启用了自己的软件包,这真是一场骚乱。
回答by Pete Wilson
One of many options is to use CPU ID. Better than Windows Registry, or network card, for example. You don't want users to bother you each time they change network card etc. I think cpuidproject can be used as an example and starting point.
许多选项之一是使用 CPU ID。例如,比 Windows 注册表或网卡更好。你不希望用户每次换网卡等都打扰你。我认为cpuid项目可以作为一个例子和起点。
回答by Michael Haephrati
Maybe this method will help you. http://www.codeproject.com/Articles/319181/Haephrati-Searching-for-a-reliable-Hardware-ID
也许这个方法会对你有所帮助。 http://www.codeproject.com/Articles/319181/Haephrati-Searching-for-a-reliable-Hardware-ID