Skip to content
Advertisement

How to get a computer specific ID number using Java

I want to create an UUID hash using a machine specific ID number other than the MAC address to validate the computer which runs the java application on. Is it possible using Java 1.8? If so, what is the best option I can choose? It would be more helpful if it will be used for both Windows and Unix platforms.

Advertisement

Answer

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.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement