How to get cpu-id in java?

Freeman picture Freeman · Feb 5, 2010 · Viewed 20k times · Source

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 ...

Answer

Steve McLeod picture Steve McLeod · Feb 5, 2010

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.