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 and colons 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 (Optional[str]) – MAC address string to clean

Return type:

Optional[str]

Returns:

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