How to obtain (almost) unique system identifier in a cross platform way?

后端 未结 4 718
一向
一向 2020-12-07 15:56

I\'m looking for a way to get a number which will almost surely change when running the code on different machines and almost surely stay the same between two runs on the sa

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-07 16:20

    I know, the question is bit too old to be answered. But I have on many occasions faced this issue. I like the accept solution, but if you have tried the code then you will know that it has issues.

    firstly the CPU id is the product ID- it is not the serial. So if you have same CPU in another Server then it is just not going to work. also the MAC Address can be changed with ease.

    If you are only trying to get this done on Linux- you could try like hal services. ie.

    hal-get-property --udi /org/freedesktop/Hal/devices/computer --key system.hardware.uuid
    

    But best thing probably to do is if you can enforce root access and if you want to get your hands dirty- is to look at the code for dmidecode. It will allow you to extract UUID of Chasis, Bios, Video and System. You cannot beat that :) and with a few tweaking you can convert it to a class.

提交回复
热议问题