Generating ID unique to a particular computer [duplicate]

ⅰ亾dé卋堺 提交于 2019-11-27 16:10:26

问题


Possible Duplicate:
Reliable way of generating unique hardware ID

Am trying to generate an ID that will be unique to a particular computer. The ID will not be generated randomly. It will be calculation based, such that the ID generated for computer A will be fixed and unique to computer A. Everytime the program is executed on computer A, it will continue to generate the same ID and when executed on another computer, it will generate another ID unique to that computer. This is to ensure that two computers don't have the same ID.

My Challenge: For my program to be able to generate an ID unique to a computer, it needs to perform the calculation based on a seed unique to the computer executing it.

My Question: How can i get a value unique to a computer, so that i can use the value as a seed in the ID generation program?

Is it possible to get a value from a computer's hardware(eg motherboard) that is unique to that computer? That way, the value is most likely not to change as long as the computer's motherboard is not replaced.


回答1:


MAC address? Thats (for practical purposes) unique to every NIC so it guarantee's reproducibility even if the user is dual booting. Sure there are rare cases of people trading cards, but coupled with other metrics (don't only use this, since network cards can be changed), it's still possible.

How would you get it?

public static byte[] getMACAddress() throws SocketException, UnknownHostException {
    InetAddress address = InetAddress.getLocalHost();
    NetworkInterface networkInterface = NetworkInterface.getByInetAddress(address);

    return networkInterface.getHardwareAddress();
}

If you want a String representation, do this

for (int byteIndex = 0; byteIndex < macAddress.length; byteIndex++) {
    System.out.format("%02X%s", macAddress[byteIndex], (byteIndex < macAddress.length - 1) ? "-" : "");
}

(thanks to http://www.kodejava.org/examples/250.html)

Note: As mentioned in the comments, Mac addresses can be spoofed. But your talking about a small part of the population doing this, and unless your using this for anti-piracy stuff, its unique enough.




回答2:


Win32 generates a computer SID, that is supposed to be unique for each installation that you can get via WMI or Active Directory, but that is pretty platform specific. You can also use the MAC address, as everyone else has mentioned, just make sure that it is a physical network adapter, as virtual adapters tend to share the same MAC address across computers.

However, UUID's (or GUID's) are 128 bit numbers that are supposed to be guaranteed unique, and were actually created for the purpose of solving the problem of generating unique identifiers across multiple, random machines. According to Wikipedia:

To put these numbers into perspective, one's annual risk of being hit by a meteorite is estimated to be one chance in 17 billion,[25] that means the probability is about 0.00000000006 (6 × 10−11), equivalent to the odds of creating a few tens of trillions of UUIDs in a year and having one duplicate. In other words, only after generating 1 billion UUIDs every second for the next 100 years, the probability of creating just one duplicate would be about 50%. The probability of one duplicate would be about 50% if every person on earth owns 600 million UUIDs.

The total number of possible combinations is 2^128 (or 3 x 10^38), so I tend to believe it. Also, most modern UUID generators don't use the V1 algorithm anymore (i.e. the one based off the MAC address), since it is considered a security issue due to the fact that one can tell when the GUID was generated, and who generated it. In the Win32 world, a security patch circa Win2K or NT 4 changed to use the V4 version of the algorithm, which is based off of a pseudo-random number instead of the MAC, and the JVM has always used the V3/V4 version.

EDIT: The method used to generate UUID's in Java is via the java.util.UUID class.




回答3:


An easy way to do this is to read the ethernet hardware, or "mac" address.

http://download.oracle.com/javase/6/docs/api/java/net/NetworkInterface.html#getHardwareAddress()

Mac addresses are not quite as unique as people think, as they do get reused as time goes on. But the odds of one application or network having two identical ones are quite low.




回答4:


The MAC address is unique enough for what you. See http://en.wikipedia.org/wiki/MAC_address

You didn't specify which language you are using. It may easier in some languages than others. Here is how to do it in Java http://www.kodejava.org/examples/250.html. Google around for your language.




回答5:


Your best option is to base the ID on the MAC address of the primary network adaptor.

This is potentially likely to change at somepoint, but so is any single hard component.

FYI GUIDs are calculated using the MAC address.




回答6:


Have you access to any information described in this article? Windows-only

http://msdn.microsoft.com/en-us/library/aa394587.aspx

Serial number, asset tag




回答7:


Another option IFF you're using intel chips is the processor serial number, assuming you can ensure the feature is enabled. See Intel Serial # Note for more info



来源:https://stackoverflow.com/questions/3644722/generating-id-unique-to-a-particular-computer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!