String mac address conversion:
def str2mac(s):
return ("%02x:" * 6)[:-1] % tuple(orb(x) for x in s)
Mac address to string:
def mac2str(mac):
return b"".join(chb(int(x, 16)) for x in plain_str(mac).split(':'))
Reference link:
https://github.com/secdev/scapy/blob/2e87889089e5593988911309bb4a1ca4f632d716/scapy/utils.py#L467