Fixed machine id (uuid.getnode)

I am trying to find something that I can use as a unique line / number for my script, which is fixed on the machine and easily accessible (cross-platform). I assume the machine will have a network card. I do not need it to be truly unique, but it is necessary that it be fixed in the long term and as little as possible.

I know that the MAC can be changed, and I will probably make a warning about it in my scenario, however I do not expect anyone to change the MAC every morning.

I came up with uuid.getnode() , but the documentation has:

If all attempts to obtain a hardware address fail, we select a random 48-bit number

Does this mean that for each function call I get a different random number, so it is impossible to use it if the MAC is not available?

... on a machine with multiple network interfaces, the MAC address of any of them can be returned.

Does this suggestion that getnode() gets a random (or first) MAC from all available? What if he gets MAC A on first start and MAC B next time? There would be no problem if I got a fixed list (sort, merge, tadaaa!)

I ask, because I have no way how to check it myself.

+10
python uuid identifier mac-address hardware
source share
3 answers

I managed to check the first part on my Android device and create an arbitrary number on every new python run, so it is not applicable for this purpose.

The second type of problem drowned itself, because if in the documents he mentioned that he can return any one of them , then this is not something you could rely on (+ I could not find a machine on which I could test it) . A good netifaces package came to the rescue, which does a similar thing

 netifaces.interfaces() # returns eg ['lo', 'eth0', 'tun2'] netifaces.ifaddresses('eth0')[netifaces.AF_LINK] # returns [{'addr': '08:00:27:50:f2:51', 'broadcast': 'ff:ff:ff:ff:ff:ff'}] 

However, I rather refused to use MAC addresses, I got something more stable.

Now to the identifiers:

1) Windows:

Doing this and getting the output can be quite good:

 wmic csproduct get UUID 

or the one I used and is available in the registry ( HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography ):

 import _winreg registry = _winreg.HKEY_LOCAL_MACHINE address = 'SOFTWARE\\Microsoft\\Cryptography' keyargs = _winreg.KEY_READ | _winreg.KEY_WOW64_64KEY key = _winreg.OpenKey(registry, address, 0, keyargs) value = _winreg.QueryValueEx(key, 'MachineGuid') _winreg.CloseKey(key) unique = value[0] 

2) Linux:

 /sys/class/dmi/id/board_serial 

or

 /sys/class/dmi/id/product_uuid 

or if not root:

 cat /var/lib/dbus/machine-id 

3) Android:

If you are working with python and don't want to interfere with the Java stuff, this should work very well:

 import subprocess cmd = ['getprop', 'ril.serialnumber'] self.unique = subprocess.check_output(cmd)[:-1] 

but if you like Java, then skip this answer , although even ANDROID_ID uniqueness is quite debatable, if it allowed to change, so, most likely, the serial number is a safer bet.

Note that, as mentioned in the linked answer, even ril.serialnumber can be empty or empty or missing (missing key). The same thing happens with the official Android API , where he clearly stated this:

The serial number of the equipment , if available.

Mac / iPhone: I could not find any solution, because I do not have access to them, but if there is a variable containing the value of the machine identifier, then you can get a simple subprocess.check_output()

+3
source share

For Mac / iphone, you can try the command below:

 import subprocess subprocess.check_output("ioreg -rd1 -c IOPlatformExpertDevice | grep -E '(UUID)'", shell=True).split('"')[-2] # for me i got it on list value -2 if having any trouble try getting it with any alternative list element. 
+1
source share

/ var / lib / dbus / machine-id can be easily faked. what about / proc / cpuinfo? ENTRY (Serial) Presumably, this is overwritten at every boot with the processor serial number

0
source share

All Articles