Browse Source

added a script just to retrieve the mac address

Maxime Alves LIRMM@home 3 years ago
parent
commit
ea7bedb64a
1 changed files with 19 additions and 0 deletions
  1. 19
    0
      pyheatpump/get_mac_address.py

+ 19
- 0
pyheatpump/get_mac_address.py View File

@@ -0,0 +1,19 @@
1
+#!/usr/bin/python3
2
+import sys
3
+def mac_address_init():
4
+    from netifaces import gateways, ifaddresses, AF_INET, AF_LINK
5
+
6
+    interface = gateways()['default'][AF_INET][1]
7
+    if len(ifaddresses(interface)) == 0:
8
+        sys.exit(1)
9
+
10
+    if len(ifaddresses(interface)[AF_LINK]) == 0:
11
+        sys.exit(1)
12
+
13
+    addr = ifaddresses(interface)[AF_LINK][0]['addr']
14
+    print(f'Got new mac address {addr}')
15
+    return addr
16
+
17
+if __name__ == "__main__":
18
+    mac_address_init()
19
+

Loading…
Cancel
Save