From 9143213d964529f15d09030973c6532e2eb6d23b Mon Sep 17 00:00:00 2001 From: Josh Cotton Date: Mon, 29 Jul 2024 23:15:02 -0700 Subject: [PATCH] Fix #585. Use /sys/class/net/IFACE/address for the MAC address instead of the ip command. --- .gitignore | 5 ++++- Obok_plugin/obok/obok.py | 10 ++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index f3f3d47..3ad6e8d 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,7 @@ # Cache /DeDRM_plugin/__pycache__ -/DeDRM_plugin/standalone/__pycache__ \ No newline at end of file +/DeDRM_plugin/standalone/__pycache__ + +# zip from make_release.py +/DeDRM_tools.zip diff --git a/Obok_plugin/obok/obok.py b/Obok_plugin/obok/obok.py index 603e773..a8379b1 100644 --- a/Obok_plugin/obok/obok.py +++ b/Obok_plugin/obok/obok.py @@ -449,9 +449,15 @@ class KoboLibrary(object): for m in matches: # print "m:{0}".format(m[0]) 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: - # probably linux - + # final fallback # let's try ip c = re.compile('\s(' + '[0-9a-f]{2}:' * 5 + '[0-9a-f]{2})(\s|$)', re.IGNORECASE) for line in os.popen('ip -br link'):