难道真的没有办法来唯一地标识的任何计算机都 [英] Is there really any way to uniquely identify any computer at all

查看:648
本文介绍了难道真的没有办法来唯一地标识的任何计算机都的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道有一些在计算器,如以下类似的问题:

I know there are a number of similar questions in stackoverflow such as the followings:

  • What's a good way to uniquely identify a computer?
  • What is a good unique PC identifier?
  • Unique computer id C#
  • WIN32_Processor::Is ProcessorId Unique for all computers
  • How to uniquely identify computer using C#?

......,数十与我研究过他们。

... and dozens more and I have studied them all.

的问题是,某些公认的答案的建议的MAC地址作为唯一标识符这是完全不正确。一些其他的答案都建议使用这似乎更合乎逻辑的各种组件的组合。然而,在使用的组合应考虑其分量是自然不可能的情况下,必须频繁地更换。前几天,我们制定了我们使用CPUID和MAC的组合来唯一标识一台Windows PC和,直到我们认为我们的方法是不够好实际测试一个软件许可问题进行密钥生成器。讽刺的是,当我们去测试它,我们发现了三个电脑回到我们的密钥生成相同的ID!

The problem is that some of the accepted answers have suggested MAC address as an unique identifier which is entirely incorrect. Some other answers have suggested to use a combination of various components which seems more logical. However, in case of using a combination it should be considered which component is naturally unlikely to be changed frequently. A few days ago we developed a key generator for a software licensing issue where we used the combination of CPUID and MAC to identify a windows pc uniquely and till practical testing we thought our approach was good enough. Ironically when we went testing it we found three computers returning the same id with our key generator!

那么,真的有什么办法来唯一确定的计算机呢?现在,我们只需要让我们的密钥生成器在Windows PC上运行。某种方式使用C#作为我们的系统是在.NET开发将是巨大的(如果可能的话)。

So, is there really any way to uniquely identify any computer at all? Right now we just need to make our key generator to work on windows pc. Some way (if possible at all) using c# would be great as our system is developed on .net.

更新:

对不起,创造一些困惑和一个显然虚惊一场。我们在检索HW信息的方法,发现了一些不正确。主要是我想删除这个问题,就像现在我自己的困惑已经和我相信,两个或多个部件的组合足以识别计算机。不过,后来我决定保留它,因为我觉得我要澄清什么导致问题,因为同样的事情可能会伤害未来其他一些人。

Sorry for creating some confusions and an apparently false alarm. We found out some incorrectness in our method of retrieving HW info. Primarily I thought of deleting this question as now my own confusion has gone and I do believe that a combination of two or more components is good enough to identify a computer. However, then I decided to keep it because I think I should clarify what was causing the problem as the same thing might hurt some other guy in future.

这是我们在做什么(不包括其他codeS):

This is what we were doing (excluding other codes):

我们使用 getManagementInfo 函数来获取MAC和处理器ID

We were using a getManagementInfo function to retrieve MAC and Processor ID

private String getManagementInfo(String StrKey_String, String strIndex)
    {
        String strHwInfo = null;
        try
        {
            ManagementObjectSearcher searcher = new ManagementObjectSearcher("select * from " + StrKey_String);
            foreach (ManagementObject share in searcher.Get())
            {
                strHwInfo += share[strIndex];
            }
        }
        catch (Exception ex)
        {
            // show some error message
        }
        return strHwInfo;
    } 

在需要的地方,我们使用该函数来获取MAC地址

然后

Then where needed we used that function to retrieve MAC Address

string strMAC = getManagementInfo("Win32_NetworkAdapterConfiguration", "MacAddress");

和检索ProcessorID

and to retrieve ProcessorID

string strProcessorId = getManagementInfo("Win32_Processor", "ProcessorId");

此时, strMAC 会如果有一个以上的包含一个以上的MAC地址。要采取只有一个,我们只是把第17个字符(12位MAC和5个冒号之间)。

At this point, strMAC would contain more than one MAC address if there are more than one. To take only one we just took the first 17 characters (12 MAC digits and 5 colons in between).

strMAC = strMAC.Length > 17 ? strMAC.Remove(17) : strMAC;

这是我们犯下的错误。因为 getManagementInfo(Win32_NetworkAdapterConfiguration的,MACADDRESS)已返回一个数字,真的是在用额外的MAC地址。例如,当我们寻找在命令提示符中的MAC地址由 getmac 命令则显示一个或两个MAC地址全部获得不同的每台PC。但 getManagementInfo(Win32_NetworkAdapterConfiguration的,MACADDRESS)返回四到五个MAC地址其中一些是对所有计算机相同。正如我们只是把我们的函数返回而不是检查别的第一个MAC地址,相同的MAC地址采取了 strMAC 顺便说一句。

This is where we made the mistake. Because getManagementInfo("Win32_NetworkAdapterConfiguration", "MacAddress") was returning a number of extra MAC addresses that were really in use. For example, when we searched for MAC addresses in the command prompt by getmac command then it showed one or two MAC addresses for each pc which were all different. But getManagementInfo("Win32_NetworkAdapterConfiguration", "MacAddress") returned four to five MAC addresses some of which were identical for all computers. As we just took the first MAC address that our function returned instead of checking anything else, the identical MAC addresses were taken in strMAC incidently.

以下code。通过<一个href=\"http://www.$c$cproject.com/Articles/28678/Generating-Unique-Key-Finger-Print-for-a-Computer\">Sowkot奥斯曼的伎俩通过返回只有第一个主动/启用MAC地址:

The following code by Sowkot Osman does the trick by returning only the first active/ enabled MAC address:

private static string macId()
    {
        return identifier("Win32_NetworkAdapterConfiguration", "MACAddress", "IPEnabled");
    }

private static string identifier(string wmiClass, string wmiProperty, string wmiMustBeTrue)
    {
        string result = "";
        System.Management.ManagementClass mc = new System.Management.ManagementClass(wmiClass);
        System.Management.ManagementObjectCollection moc = mc.GetInstances();
        foreach (System.Management.ManagementObject mo in moc)
        {
            if (mo[wmiMustBeTrue].ToString() == "True")
            {
                //Only get the first one
                if (result == "")
                {
                    try
                    {
                        result = mo[wmiProperty].ToString();
                        break;
                    }
                    catch
                    {
                    }
                }
            }
        }
        return result;
    }
    //Return a hardware identifier
    private static string identifier(string wmiClass, string wmiProperty)
    {
        string result = "";
        System.Management.ManagementClass mc = new System.Management.ManagementClass(wmiClass);
        System.Management.ManagementObjectCollection moc = mc.GetInstances();
        foreach (System.Management.ManagementObject mo in moc)
        {
            //Only get the first one
            if (result == "")
            {
                try
                {
                    result = mo[wmiProperty].ToString();
                    break;
                }
                catch
                {
                }
            }
        }
        return result;
    }

不过,我是绝对正确相同的处理器ID的问题。所有这三个返回相同的处理器ID,当我们把 WMIC CPU中的命令提示符得到ProcessorId 命令。

现在,我们已经决定使用主板序列号,而不是处理器ID,以MAC地址的组合。我认为,我们的目的将这种方式送达,如果它在某些情况下不能做那么,我们应该让它在那几个案件去了。

Now we have decided to use Motherboard serial number instead of Processor ID to make a combination with MAC address. I think our purpose will be served with this way and if it doesn't in some cases then we should let it go in those few cases.

推荐答案

在获得一个全球唯一的ID事实是,只有MAC地址,如果你设置系统遍布不会改变的ID。如果要生成特定产品的关键,最好的办法做到这一点的产品分配唯一ID,并结合MAC地址的产品ID。希望它帮助。

The fact in getting a globally unique ID is, only MAC address is the ID that will not change if you set up your system all over. IF you are generating a key for a specific product, the best way to do it is assigning unique IDs for products and combining the product ID with MAC address. Hope it helps.

这篇关于难道真的没有办法来唯一地标识的任何计算机都的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆