Settings

class getmac.variables.Settings[source]

Bases: VarsClass

User-configurable settings.

Attributes Summary

ARP_TIMEOUT

How long to keep checking the ARP table (IPv4) or NDP list (IPv6) for a host, in seconds, after sending the UDP packet to populate it (see PORT).

COMMAND_TIMEOUT

How long to wait for a command that getmac runs (e.g. arp or ipconfig.exe) to finish, in seconds.

DEBUG

Debugging level.

FORCE_METHOD

Force a specific method to be used for all lookups.

OVERRIDE_PLATFORM

User-configurable override to force a specific platform.

PORT

UDP port to use for populating the ARP table (IPv4) or NDP list (IPv6) when looking up MACs for hosts or IPs.

Attributes Documentation

ARP_TIMEOUT: float = 0

How long to keep checking the ARP table (IPv4) or NDP list (IPv6) for a host, in seconds, after sending the UDP packet to populate it (see PORT).

The host’s entry is only added once it replies, which often takes longer than getmac takes to check the table. If it isn’t there, getmac checks again with short, growing delays until the host is found or this much time has passed. Lookups of hosts that don’t reply take this much longer. 0 (the default) checks once, without waiting.

This doesn’t apply when getmac sends an ARP request itself and waits for the reply instead (ArpingHost or CtypesHost). On the command line, use --arp-timeout.

COMMAND_TIMEOUT: Optional[float] = 15.0

How long to wait for a command that getmac runs (e.g. arp or ipconfig.exe) to finish, in seconds. A command that takes longer is stopped, and the method that ran it is treated as failed, so the next method is tried.

This keeps a lookup from hanging forever on a command that never exits. Commands usually finish in well under a second, but some, such as arp without -n on macOS, can be slow due to DNS lookups. None or 0 waits for as long as the command takes, and so does a value that can’t be waited for (negative, infinity, or more than a day). On the command line, it’s --command-timeout.

DEBUG: int = 0

Debugging level. A higher value means more output. 4 is roughly the highest.

  • 0 (the default): warnings and errors, plus a few debug messages, such as when a cache is built and the raw MAC that was found.

  • 1: the methods that failed their test, the contents of the caches, each lookup attempt, and how long the lookup took.

  • 2: the methods left after filtering by type, by platform, and by their test.

  • 3: every command that’s run.

  • 4: the output of every command, and the full list of methods.

Nothing is shown until logging is configured, e.g. with logging.basicConfig(). On the command line, use -d (once per level, e.g. -dddd for level 4).

FORCE_METHOD: str = ''

Force a specific method to be used for all lookups. Used for debugging and testing.

The value is a method class name, e.g. "IpNeighborShow", matched ignoring case. It’s checked on every lookup. When it’s set:

  • A new instance of the method is created for each lookup.

  • test() is not called, and the method type and platforms of the method are ignored.

  • There’s no fallback, and exceptions raised by the method are not caught.

  • If no method has that name, an error is logged and None is returned.

On the command line, use --force-method.

OVERRIDE_PLATFORM: str = ''

User-configurable override to force a specific platform.

Methods for this platform are used instead of the methods for the detected platform, PLATFORM. Use a platform identifier such as "linux" or "wsl", or any value returned by platform.system(), such as "Darwin". Case and surrounding whitespace are ignored. An empty string (the default) means no override.

It’s only read when the method cache for a lookup type is built, so set it before the first lookup (or reset the caches). On the command line, use --override-platform.

PORT: int = 55555

UDP port to use for populating the ARP table (IPv4) or NDP list (IPv6) when looking up MACs for hosts or IPs. On the command line, use --override-port.