Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generating ID unique to a particular computer [duplicate]

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.

like image 993
Dami Lola Avatar asked Sep 05 '10 01:09

Dami Lola


People also ask

What is the unique identifier of a computer?

A universally unique identifier (UUID) is a 128-bit label used for information in computer systems. The term globally unique identifier (GUID) is also used. When generated according to the standard methods, UUIDs are, for practical purposes, unique.

How is hardware ID generated?

The hardware IDs for a computer can be generated by running the ComputerHardwareIds tool (ComputerHardwareIDs.exe), which is included in the Windows Driver Kit (WDK) for Windows 7, Windows 8 and Windows 8.1. Beginning with Windows 10, the ComputerHardwareIds tool is included in the Software Development Kit (SDK).


1 Answers

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.

like image 98
TheLQ Avatar answered Oct 05 '22 23:10

TheLQ