get_mac_address

getmac.getmac.get_mac_address(interface=None, ip=None, ip6=None, hostname=None, network_request=True)[source]

Get a MAC address from a local interface or remote host.

Only ONE of the first four arguments may be used: interface, ip, ip6, or hostname. If none of the arguments are selected, the default network interface for the system will be used.

The MAC is usually a unicast IEEE 802 MAC-48 address.

Note

"localhost" or "127.0.0.1" will always return "00:00:00:00:00:00"

Note

It is assumed that the host is using Ethernet or Wi-Fi. While other protocols such as Bluetooth may work, this has not been tested and should not be relied upon. If this functionality is needed, please open an issue or PR.

Note

Exceptions raised by methods are handled silently and returned as None.

Parameters:
Return type:

Optional[str]

Returns:

Lowercase colon-separated MAC address. If no MAC was found, or an exception occurred, None is returned.

Raises:

RuntimeError – If no valid methods are found for the type of MAC requested, or another critical error occurs (potentially due to a bug in getmac).