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?
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.
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.
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
)
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.
精彩评论