get_by_method

getmac.getmac.get_by_method(method_type, arg='', network_request=True)[source]

Query for a MAC using a specific method.

Parameters:
  • method_type (str) – the type of lookup being performed. Allowed values are: ip4, ip6, iface, default_iface

  • arg (str) – Argument to pass to the method, e.g. an interface name or IP address

  • network_request (bool) – if methods that make network requests should be included (those methods that have the attribute network_request set to True)

Return type:

Optional[str]

Returns:

The raw value the method found (a MAC that hasn’t been cleaned up, or for default_iface, the name of an interface), or None if nothing was found

Raises:

RuntimeError – if no method can be used for the given method type, e.g. none of them match the platform, or they all failed their test.