Click here to Skip to main content
15,887,371 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am going to write a small python script. which
gets unique id of device if result same with before generated so program run, else stops. I have tried bu uuid but uuid is generating different id codes every time. I am going to
provide my code sample here.

What I have tried:

from uuid import getnode as get_mac


mac = get_mac()
if mac == "0xeb59894bba43": #it is first generated id. it is changing every time
print('activated')
else:
print('not activated')
exit()
Posted
Updated 16-Oct-22 20:16pm

1 solution

Look at the documentation:
uuid.getnode()
Get the hardware address as a 48-bit positive integer. The first time this runs, it may launch a separate program, which could be quite slow. If all attempts to obtain the hardware address fail, we choose a random 48-bit number with the multicast bit (least significant bit of the first octet) set to 1 as recommended in RFC 4122. “Hardware address” means the MAC address of a network interface. On a machine with multiple network interfaces, universally administered MAC addresses (i.e. where the second least significant bit of the first octet is unset) will be preferred over locally administered MAC addresses, but with no other ordering guarantees.

Look at your returned value: 0xeb59894bba43 and the first octet value is hex EB - in binary that's 11101011 which means that the least significant bit is set to 1, so that's a multicast address, which means it's returning a random number (which is why it changes each time you try it), which means that "all attempts to obtain the hardware address" failed.

Go back to your previous question on this subject: How to protect Python script running in other devices[^] and look at Richard's answer.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900