简体   繁体   中英

How can I create unique identifiers for each machine in Linux or Perl?

I have a Perl script running in many machines, the script will store some data into a MySQL Database. I need to know the source of data.

I cannot use hostname , because some machines's hostname is 'localhost'.

ifconfig gives random devices and IP, some eth0 ,some eth1 ,some other device name.

Is there any other way to create unique identifiers for each machine? And everytime I run the Perl script, this unique identifier does not change.

You can try uuid.

uuid - DCE compatible Universally Unique Identifier library

here

除了先前对genhostid的调用之外,还应该使用hostid ,该调用将生成并存储机器的唯一ID(因此,每次调用该ID都不会改变)。

The output from dmidecode provides a number of hardware UUID & serial numbers which your perl script could take advantage of. To quote the man page for dmidecode:

  dmidecode is a tool for dumping a computer's DMI (some say SMBIOS) table contents in a human-readable format. This table contains a description of the system's hardware components, as well as other useful pieces of information such as serial numbers and BIOS revision. 

The best way I've found is to generate a file with a random ID the first time, and use the file contents once the file exists. I put it in /etc somewhere, but it doesn't matter.

This is tolerant of system configuration changes, but requires some extra work to interrogate remotely.

take MAC address and modify it?

ipconfig -a

or

arp

and parse?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM