ArpingHost

class getmac.getmac.ArpingHost[source]

Bases: Method

Use arping command to determine the MAC of a host on Linux and Darwin (MacOS).

This method supports three variants of arping:

  • “habets” arping by Thomas Habets

    (GitHub) On Debian-based distros, apt install arping will install Habets arping.

  • “iputils” arping, from the

    iputils-arping package

  • “busybox” arping, included with BusyBox (a small executable “distro”)

    (further reading)

BusyBox’s arping quite similar to iputils-arping. The arguments for our purposes are the same, and the output is also the same. There’s even a TODO in BusyBox’s arping code referencing iputils arping. There are several differences:

  • The return code from bad arguments is 1, not 2 like for iputils-arping

  • The MAC address in output is lowercase (vs. uppercase in iputils-arping)

This was a pain to obtain samples for busybox on Windows. I recommend using WSL and arping’ing the Docker gateway (for WSL2 distros). Note, it must be run as root using sudo busybox arping.

Attributes Summary

method_type

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

network_request

If the method makes a network request as part of the check.

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 = 'ip4'

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

Allowed values:

  • ip

  • ip4

  • ip6

  • iface

  • default_iface

network_request: bool = True

If the method makes a network request as part of the check.

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

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