python - Fixed identifier for a machine (uuid.getnode) -


i'm trying find can use unique string/number script fixed in machine , obtainable(cross-platform). presume machine have network card. don't need unique, necessary should fixed in long run , rare possible.

i know mac can changed , i'd make warning in script, don't expect change mac each morning.

what came uuid.getnode(), in docs there is:

if attempts obtain hardware address fail, choose random 48-bit number

does mean each function call random number, therefore it's not possible use if mac unobtainable?

...on machine multiple network interfaces mac address of 1 of them may returned.

does sentence mean getnode() gets random(or first) mac available? if it'd mac in first run , mac b next time? there'd no problem if i'd fixed list(sort, concatenate, tadaaa!)

i'm asking because have no way how test myself.

i managed test first part on android device , on each new python run created random number, it's not usable @ purpose.

the second problem kind of drowned itself, because if in docs mentioned may return any 1 of them, it's not rely on (+i couldn't find machine test on). nice package netifaces came rescue, similar thing

netifaces.interfaces() # returns e.g. ['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 rather gave using macs, got rather more stable.

now identifiers:

1) windows:

executing 1 , getting output may enough:

wmic csproduct uuid 

or 1 used , available in 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 working python , don't want mess java stuff, should work pretty good:

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

but if java, go this answer although android_id's uniqueness rather debatable if it's allowed change, therefore serial number safer bet.

note it's mentioned in linked answer, ril.serialnumber can null/empty or non-existing (missing key). same thing happens official android api it's stated this:

a hardware serial number, if available.

mac/iphone: couldn't find solution don't have access of these, if there variable holds machine id value, should able there simple subprocess.check_output()


Comments