Projet de remplacement du "RPiPasserelle" d'Otec.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

get_mac_address.py 467B

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