Getting a unique id from a unix-like system

前端 未结 15 2385
不知归路
不知归路 2020-11-27 18:22

I want to get from any Unix-like system (if this is possible) a unique id that will be persistent every time my application runs in the same machine. If it is possible, I wa

15条回答
  •  离开以前
    2020-11-27 19:17

    The best way is, as usual, to see how other people already solved the same problem.

    FLEXlm also uses a host identifier for its node-locked licenses. The most common host identifier it uses is the ethernet MAC address for one of your network interfaces, smashed together without any separator.

    It can also use (on Windows) the volume serial number of the C: drive (again smashed together without any separators), and on Solaris the output of the hostid command (IIRC, on Sun computers, this number is actually unique, and located on a small removable EEPROM on the system board).

    While the MAC address is extremly easy to fake, it is a nearly universal identifer nowadays (almost all new computers have at least one ethernet port, and it is very common for them to be onboard), and actually intended to be globally unique (in fact, the Ethernet protocols depend on this uniqueness). The main problems you would have with this approach:

    • Some computers have several ethernet addresses; some of them are on the main board, some are on separate removable cards.
    • They are extremly easy to fake (and some protocols depend on being able to change them).
    • Some virtualized environment generate random ethernet addresses on each boot (but they usually have a way to force a fixed value).

提交回复
热议问题