helper.py 743 B

1234567891011121314151617181920212223242526272829303132
  1. #!/usr/bin/env python3
  2. import netifaces as netif
  3. import subprocess
  4. def toUTF8(line):
  5. return line.decode("utf-8")
  6. def call(cmdnargs):
  7. output = subprocess.check_output(cmdnargs)
  8. lines = output.splitlines()
  9. lines = [toUTF8(line) for line in lines]
  10. return lines
  11. def merge(a, b):
  12. if isinstance(a, dict) and isinstance(b, dict):
  13. d = dict(a)
  14. d.update({k: merge(a.get(k, None), b[k]) for k in b})
  15. return d
  16. if isinstance(a, list) and isinstance(b, list):
  17. return [merge(x, y) for x, y in itertools.izip_longest(a, b)]
  18. return a if b is None else b
  19. def getDevice_MAC(dev):
  20. try:
  21. interface = netif.ifaddresses(dev)
  22. mac = interface[netif.AF_LINK]
  23. return mac[0]['addr']
  24. except:
  25. return None