0

Possible Duplicate:
How to get a unique computer identifier in Java (like disk id or motherboard id)
Need to identify local machine somehow in java

I want to get some sort of unique ID for the computer (ie IP address).

I have tried:

InetAddress inetAddress = null; try { inetAddress = InetAddress.getLocalHost(); } catch (final UnknownHostException ex) {} return inetAddress.getHostAddress(); 

This gives an IP, but this one seems to change periodically. Is there a way to get one the DOES NOT change?

Thanks in advance!

NOTE:

I need to be able to associate this ID with the computer.

5
  • 1
    What if the user buys a new hard drive? Commented Jan 25, 2012 at 23:25
  • Note that local IPs are very non-unique. Commented Jan 25, 2012 at 23:26
  • Maybe the MAC address? Though that could change too if they replaced the network interface. Commented Jan 25, 2012 at 23:26
  • @MikeChristensen: Especially on a laptop with WiFi disabled (and sometimes a wired connection) Commented Jan 25, 2012 at 23:27
  • do CPUs have something like a vehicle identification number? Commented Jan 25, 2012 at 23:29

1 Answer 1

2

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()

Sign up to request clarification or add additional context in comments.

7 Comments

Will this address NOT change?
Yep the MAC address is clearly the best choice here. Ignoring some rare situations (say VMs, someone changing the MAC address) it's guaranteed to be globally unique - what else could you want. Although it still can change - we could swap the network card or install a second one, etc.
Could I get help with adding code for this? I can't seem to get it right.
How hard have you tried in 5 minutes? :-)
It keeps on saying: "non-static method getHardwareAddress() cannot be referenced from a static context." No matter what I do, I can't get it. Happy?
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.