0

My python application running as a daemon in a variety of linux distributions are trying to register to my server using the machine's IP Address and FQDN Hostname(given by "hostname -f" command) as a primary key.

Now I am facing a problem when two machines are having same hostname and IP Address. Eg in case of two VM's running on two seperate machines, the hostname is "localhost.localdomain" and Ip Address is "192.168.0.2" for both of them.

Is there any unique way to differentitate any two machines. (Maybe some other third parameter which will guarantee uniqueness across any linux machine )

tarun_2709
  • 21
  • 5

1 Answers1

2

the MAC address should be unique per network interface. maybe you can try a combination of IP, MAC and host name?

another option is to create a UUID and save it on the machine.

assaf
  • 210
  • 2
  • 9
  • Using MAC Address is also tricky as the python uuid docs mention (https://docs.python.org/2/library/uuid.html#uuid.getnode ) that the getnode function returns the MAC address randomly from any one of the interfaces. This is also strongly discouraged at http://stackoverflow.com/questions/159137/getting-mac-address#comment49688_159195 Please let me know if there is any way to determine the primary MAC address using python. – tarun_2709 Apr 28 '15 at 20:29
  • I think that the best way is to generate a random uuid and save it on the local machine, so you can identify your self with it to your server. also the getnode will do the job as long as you save the results on the machine and reuse it. – assaf Apr 28 '15 at 20:34
  • The problem is that this application is running in a large number (thousands) of user machines not just locally in my machine. Your solution only increases the chances of me getting a "duplicate primary key error" overtime. – tarun_2709 Apr 28 '15 at 20:51
  • as [this](http://en.wikipedia.org/wiki/Universally_unique_identifier#Random%5FUUID%5Fprobability%5Fof%5Fduplicates) article states, the odds are very small for a duplicate uuid... if you add to it your host name, I don't think it will ever happen. – assaf Apr 28 '15 at 20:57
  • you can also see [this](http://stackoverflow.com/questions/1155008/how-unique-is-uuid) thread. – assaf Apr 28 '15 at 20:58
  • A type 4 UUID has 122 random bits. With only "thousands" of user machines, you're more likely to be hit in the head by a meteorite a million times over than have a uuid collision.. – janneb Apr 28 '15 at 21:01