clean_mac

getmac.utils.clean_mac(mac)[source]

Check and format a string result to be lowercase colon-separated MAC.

It will clean out any garbage and ensure the length, colons and hexadecimal digits are correct, and replace - characters with : characters.

If string is invalid after as much cleanup as possible, then None is returned. The specific issue is logged as a warning.

Parameters:

mac (Union[str, bytes, None]) – MAC address string to clean (bytes are decoded as UTF-8)

Return type:

Optional[str]

Returns:

Cleaned and formatted MAC address string, or None if validation failed.