Getting a unique id from a unix-like system

前端 未结 15 2465
不知归路
不知归路 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:03

    You don't mention how stable the unique identifier needs to be -- do you always want the same host to produce the same ID each time your code is run?

    If no, then fuzzymonk's suggestion of uuidgen is what you want.

    If yes, then you need to decide what constitutes "same" as far as the host as concerned. One way would be as you suggest, the MD5 sum of the MAC of the first ethernet interface and "something". For "something" in that case I would consider the FQDN, unless your notion of "same host" includes the FQDN changing...

提交回复
热议问题