]> xmof Git - DeDRM.git/commitdiff
Fix Obok import in Calibre flatpak by using /sys/class/net/IFACE/address instead...
authorJosh Cotton <jcotton42@users.noreply.github.com>
Sun, 10 Nov 2024 13:14:59 +0000 (05:14 -0800)
committerGitHub <noreply@github.com>
Sun, 10 Nov 2024 13:14:59 +0000 (13:14 +0000)
Fix #585.
Use /sys/class/net/IFACE/address for the MAC address instead of the ip
command.

Obok_plugin/obok/obok.py

index 603e77393c91cc77a3f5a885800d9fd0b341045c..a8379b1ce4ef1da545e8e1b53c4465b5ce596c54 100644 (file)
@@ -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'):