13 lines
407 B
Python
13 lines
407 B
Python
def parse_mac(value):
|
|
raw = value.strip().lower().replace(":", "").replace("-", "")
|
|
if len(raw) != 12:
|
|
raise ValueError("address must be 12 hex chars or aa:bb:cc:dd:ee:ff")
|
|
try:
|
|
return bytes.fromhex(raw)
|
|
except ValueError:
|
|
raise ValueError("address contains non-hex characters")
|
|
|
|
|
|
def format_mac(mac_bytes):
|
|
return ":".join("{:02x}".format(b) for b in mac_bytes)
|