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.
 
 
 
 

25 regels
872 B

  1. import re
  2. def norm_mac(mac: str) -> str:
  3. """Ritorna MAC come AA:BB:CC:DD:EE:FF (upper), ignorando separatori."""
  4. if not mac:
  5. return ""
  6. m = str(mac).strip().replace("-", "").replace(":", "").replace(".", "")
  7. m = m.upper()
  8. if len(m) != 12:
  9. return mac.strip().upper()
  10. return ":".join(m[i:i+2] for i in range(0, 12, 2))
  11. def is_mac(mac: str) -> bool:
  12. """Verifica se la stringa è un MAC valido."""
  13. if not mac: return False
  14. m = str(mac).strip().replace("-", "").replace(":", "").replace(".", "")
  15. return len(m) == 12 and all(c in "0123456789ABCDEFabcdef" for c in m)
  16. # Alias per compatibilità con gli altri script (gateways.py e train_collect.py)
  17. normalize_mac = norm_mac
  18. def mac_to_compact(mac: str) -> str:
  19. """Ritorna MAC senza separatori (es: AC233FC1DD3C)."""
  20. return norm_mac(mac).replace(":", "").upper()