How to Get a Unique Computer Identifier in Java (Like Disk Id or Motherboard Id)

How to get a unique computer identifier in Java (like disk ID or motherboard ID)?

It is common to use the MAC address is associated with the network card.

The address is available in Java 6 through through the following API:

Java 6 Docs for Hardware Address

I haven't used it in Java, but for other network identification applications it has been helpful.

How to get a computer specific ID number using Java

Yes. You can do it without MAC address in both PC as well as linux systems.

I am going to break the process in steps.

Step1: Identify OS
In Your java code, identify the OS used like this

private static String OS = System.getProperty("os.name").toLowerCase();
if(OS.indexOf("win") >= 0)
//your code for windows OS.
else if(OS.indexOf("mac") >= 0)
//your code for MAC OS.
else if(OS.indexOf("sunos") >= 0)
//your code for Solaris OS
else if(OS.indexOf("nix") >= 0 || OS.indexOf("nux") >= 0 || OS.indexOf("aix") > 0 )
//your code for unix OS's

Step 2: use required commands to get the UUID of a system
What is a UUID?

A universally unique identifier (UUID) is a 128-bit number used to identify information in computer systems.

For windows

Runtime.exec("wmic csproduct get UUID");

The cmd command wmic csproduct get UUID returns the UUID of PC [windows]

For Linux
use this kernal command with Runtime.exec("YOUR COMMAND")

# cat /sys/class/dmi/id/product_uuid

To know more about Runtime.exec check this java.lang.Runtime.exec

java.lang.Runtime.exec : Through this, you supply the appropriate shell command for any underlying Environment, whether be MAC, Windows, Linux etc.

Unique computer ID hardware based in Java

How much is your software worth ?

Does the target market pirate software a lot ?

Motherboard serial number reading is possible on Windows boxes using WMI

Use WMI to read serial number
http://www.c-sharpcorner.com/UploadFile/GemingLeader/mb-sn-wmi08242009101325AM/mb-sn-wmi.aspx

Use WMI from Java
http://henryranch.net/software/jwmi-query-windows-wmi-from-java/

WMI is/was a broken on Windows XP domain members on a AD Domain, if they use group policies.

( This only effects most corporate users of XP, so not a big deal)

Hope this helps a bit ( MAC address is simpler... but is easy to change)

Java - How to Get a Unique Number from Computer

If the machine is on DHCP, the IP address will change periodically. You could use the hostname, or you could use the MAC address, which you can get with java.net.NetworkInterface.getHardwareAddress()

How to get cpu-id in java?

if you need unique id you can use UUID :

import java.util.UUID;

public class GenerateUUID {

public static final void main(String... aArgs){
//generate random UUIDs
UUID idOne = UUID.randomUUID();
UUID idTwo = UUID.randomUUID();
log("UUID One: " + idOne);
log("UUID Two: " + idTwo);
}

private static void log(Object aObject){
System.out.println( String.valueOf(aObject) );
}
}

Example run :

>java -cp . GenerateUUID
UUID One: 067e6162-3b6f-4ae2-a171-2470b63dff00
UUID Two: 54947df8-0e9e-4471-a2f9-9af509fb5889

Computer specific ID?

I actually do believe you should use something from hardware profile.

A computer can be considered as a set of pieces of hardware, including the network interface.
A typical pattern can be to have combination of a MAC address and a generated ID by a management system that manages computers over the network.

The MAC address to identify uniquely the machine during a registration process to the management system.

As a result of the registration, the management system can return a generated UniqueId,

to be stored on the computer that registered to it, and will later on be used.

After a successful registration, you can replace the network interface card, as the computer does not depend on the MAC address to be identified.

You can also consider using the linux dmidecode utility
(for linux machines,
as you provided a win-based solution,
so for our linux readers,
I would like to suggest a linux alternaties) (if the machine you want to uniquely identify has linux and dmidecoe installed).

Using dmidecoe you can get more hardware profile, and perform some hash function on it, and generate a unique ID that will identify uniquely (with high probability, to be precise) your machine.

Read more about dmidecode here.

Of course, in case you go to "get information on hardware from the operating system" approach (which is dmidecode or what you suggested at the part after getting the MAC address,

You need for a cross platform code to check what is the OS the java program runs on, you do that using this:

System.getProperty("os.name");

What's MAC address ? What is a unique ID for a PC?

MAC stands for Media Access Control. The MAC address usually represents a unique id for your network adapter(s). You must have two network adapters in your pc (LAN, WLAN?).

Have a look here this describes how to get a unique system identifier in JAVA:
How to get a unique computer identifier in Java (like disk id or motherboard id)

And .NET:
http://sowkot.blogspot.com/2008/08/generating-unique-keyfinger-print-for.html

Michael



Related Topics



Leave a reply



Submit