DefaultIfaceLinuxRouteFile

class getmac.getmac.DefaultIfaceLinuxRouteFile[source]

Bases: Method

Determine the default interface by parsing the /proc/net/route file on Linux-based platforms (including WSL).

This is the same source as the route command, however it’s much faster to read this file than to call route. If it fails for whatever reason, we can fall back on the system commands (e.g for a platform that has a route command, but doesn’t use /proc, such as BSD-based platforms).

Attributes Summary

method_type

The type of method, e.g. does it get the MAC of a interface.

platforms

Platforms supported by a method.

Methods Summary

get([arg])

Core logic of the method that performs the lookup.

test()

Low-impact test that the method is feasible, e.g. a command exists.

Attributes Documentation

method_type: str = 'default_iface'

The type of method, e.g. does it get the MAC of a interface.

Allowed values:

  • ip

  • ip4

  • ip6

  • iface

  • default_iface

platforms: Set[str] = {'linux', 'wsl'}

Platforms supported by a method.

Methods Documentation

get(arg='')[source]

Core logic of the method that performs the lookup.

Warning

If the method itself fails to function an exception will be raised! (for instance, if some command arguments are invalid, or there’s an internal error with the command, or a bug in the code).

Parameters:

arg (str) – What the method should get, such as an IP address or interface name. In the case of default_iface methods, this is not used and defaults to an empty string.

Return type:

Optional[str]

Returns:

Lowercase colon-separated MAC address, or None if one could not be found.

test()[source]

Low-impact test that the method is feasible, e.g. a command exists.

Return type:

bool