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