Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get cpu-id in java?

I want to create an encryption with java.
Is there anyway to get CPU Id or anything that be unique in PC such as BIOS or ...

for example System.getCpuId(); it is just an example 😉

Thanks a lot ...

like image 756
Freeman Avatar asked Feb 05 '10 11:02

Freeman


People also ask

How do I find my CPU ID?

Highlight the "My Computer" desktop icon and right mouse click, select "Properties", then select "Network Identification" and your cpuid is located there.


2 Answers

So you want a unique number (or string?) that identifies the user's computer? Or at least unique enough that the chance of a duplicate is very low, right?

You can get the Mac address of the network interface. This is making many assumptions, but it may be good enough for your needs:

final byte[] address = NetworkInterface.getNetworkInterfaces().nextElement().getHardwareAddress();
System.out.println("address = " + Arrays.toString(address));

This gives you an array of bytes. You can convert that to an id in several ways... like as a hex string.

Expect support though, when people replace bits of hardware in their computer.

like image 108
Steve McLeod Avatar answered Oct 02 '22 01:10

Steve McLeod


I think such OS specific command is not available in Java.

This link shows a way to run it on windows.

like image 24
Laurent K Avatar answered Oct 02 '22 01:10

Laurent K