Use /sys/class/net/IFACE/address for the MAC address instead of the ip
command.
This commit is contained in:
Josh Cotton 2024-07-29 23:15:02 -07:00
parent 3373d93874
commit 9143213d96
2 changed files with 12 additions and 3 deletions

5
.gitignore vendored
View file

@ -6,4 +6,7 @@
# Cache # Cache
/DeDRM_plugin/__pycache__ /DeDRM_plugin/__pycache__
/DeDRM_plugin/standalone/__pycache__ /DeDRM_plugin/standalone/__pycache__
# zip from make_release.py
/DeDRM_tools.zip

View file

@ -449,9 +449,15 @@ class KoboLibrary(object):
for m in matches: for m in matches:
# print "m:{0}".format(m[0]) # print "m:{0}".format(m[0])
macaddrs.append(m[0].upper()) macaddrs.append(m[0].upper())
elif sys.platform.startswith('linux'):
for interface in os.listdir('/sys/class/net'):
with open('/sys/class/net/' + interface + '/address', 'r') as f:
mac = f.read().strip().upper()
# some interfaces, like Tailscale's VPN interface, do not have a MAC address
if mac != '':
macaddrs.append(mac)
else: else:
# probably linux # final fallback
# let's try ip # let's try ip
c = re.compile('\s(' + '[0-9a-f]{2}:' * 5 + '[0-9a-f]{2})(\s|$)', re.IGNORECASE) c = re.compile('\s(' + '[0-9a-f]{2}:' * 5 + '[0-9a-f]{2})(\s|$)', re.IGNORECASE)
for line in os.popen('ip -br link'): for line in os.popen('ip -br link'):