I am building a Java desktop app, and I'd like to be able to uniquely identify which machine the code is currently running on. (It doesn't need to be any personal data; it just needs to be able to distinguish one machine from another, and to be sure that it won't change if the machine stays the same, short of an OS reinstall.) Ideally, it would be platform independent. Any advice on how to do this?
-
1Yes, could you provide more info on why you need this and what the end goal is? That may help us make better recommendations for how it could be handled. – jmichalicek Mar 28 '11 at 00:39
4 Answers
You can use the MAC address of your network hardware. Usually this will even survive OS reinstalls.
I did this years ago when I wrote my own lab management software for test automation, and had to uniquely identify machines. They grabbed a script from a known network share, with the file name matching their MAC address. I did this because I was testing OS setup, and my automation had to survive reboots.
This example seems to show how to do that. I don't use Java, though, so I can't tell you if it is old style, or there is a better way to do it:
http://www.kodejava.org/examples/250.html
Be warned that if you're looking to solve a problem related to software licensing, this is in no way hack-proof. In fact, you can spoof just about any unique hardware identifier.

- 58,163
- 16
- 128
- 183
-
That assumes that the nic does not get changed and that the same nic is always selected if there are multiple nics. Not saying it's a bad idea, all options I can think of have some way that the user can make a change and screw things up. Just making sure it's noted in case the OP goes this route. – jmichalicek Mar 28 '11 at 00:05
-
@jmichalicek: I fully agree. If this needs to be fool-proof or "unhackable" then he's going to have to go with another option, like running his software as a web application, and using user authentication. – Merlyn Morgan-Graham Mar 28 '11 at 00:34
-
You could have the app create a guid/uuid when it is installed and store that somewhere to be used wherever this unique id is needed. Have a look at java.util.UUID
for creating these in Java.

- 26,356
- 27
- 122
- 180

- 2,398
- 1
- 17
- 7
-
It wouldn't be installed, it would be a JAR that is run. If the jar was downloaded and run again, I'd like it to detect that the machine is the same. – Nick Heiner Mar 27 '11 at 23:59
-
You could still save that uuid somewhere local on the computer and check for it when the app runs and see what the uuid is if it exists, otherwise create it. There's risk of them deleting the file if this is not in a controlled environment, but there are very few ways to do this that the user absolutely cannot screw up due to making changes on their computer in an uncontrolled environment. – jmichalicek Mar 28 '11 at 00:03
Answers to this SO question suggest many approaches. The most common suggestion is to use the MAC address. From what I can tell, there doesn't seem to be a way that is 100% reliable - I think you'll have to make a call on how badly you need to track returning users and how much effort you want to spend on implementing this feature.

- 1
- 1

- 20,221
- 2
- 60
- 51
Use the MAC address of the computer. It's already a (somewhat) unique identifier.
This blog has some details with a UUID class (not the same as java.util
)