|
@@ -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
|
+
|