Skip to content

Commit

Permalink
Fix Obok import in Calibre flatpak by using /sys/class/net/IFACE/addr…
Browse files Browse the repository at this point in the history
…ess instead of `ip` (#586)

Fix #585.
Use /sys/class/net/IFACE/address for the MAC address instead of the ip
command.
  • Loading branch information
jcotton42 authored Nov 10, 2024
1 parent 2cd2792 commit 808dc7d
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions Obok_plugin/obok/obok.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,9 +449,15 @@ def __getmacaddrs (self):
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'):
Expand Down

0 comments on commit 808dc7d

Please sign in to comment.