API

Full API reference for the getmac package.

getmac.getmac Module

Get the MAC address of remote hosts or network interfaces.

It provides a platform-independent interface to get the MAC addresses of:

  • System network interfaces (by interface name)

  • Remote hosts on the local network (by IPv4/IPv6 address or hostname)

The key function is get_mac_address().

Examples
from getmac import get_mac_address

eth_mac = get_mac_address(interface="eth0")
win_mac = get_mac_address(interface="Ethernet 3")
ip_mac = get_mac_address(ip="192.168.0.1")
ip6_mac = get_mac_address(ip6="::1")
host_mac = get_mac_address(hostname="localhost")
updated_mac = get_mac_address(ip="10.0.0.1", network_request=True)

Functions

get_by_method(method_type[, arg, ...])

Query for a MAC using a specific method.

get_default_interface()

Get the name of the default network interface on the system.

get_instance_from_cache(method_type, method_name)

Get the class for a named Method from the caches.

get_mac_address([interface, ip, ip6, ...])

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

get_method_by_name(method_name)

initialize_method_cache(method_type[, ...])

Initialize the method cache for the given method type.

Classes

ArpExe()

Query the Windows ARP table using arp.exe to find the MAC address of a remote host.

ArpFile()

Use the contents of /proc/net/arp to find the MAC address of a host.

ArpFreebsd()

Use the arp command to find the MAC address of a host on FreeBSD.

ArpOpenbsd()

Use the arp command to find the MAC address of a host on OpenBSD.

ArpVariousArgs()

Use the arp command to find the MAC address of a host on various platforms.

ArpingHost()

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

CtypesHost()

Uses SendARP from the Windows Iphlpapi to get the MAC address of a remote IPv4 host.

DarwinNetworksetupIface()

Use networksetup on MacOS (Darwin) to get the MAC address of a specific interface.

DefaultIfaceFreeBsd()

Determine the default interface on FreeBSD using the netstat command.

DefaultIfaceIpRoute()

Determine the default interface using the ip route command.

DefaultIfaceLinuxRouteFile()

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

DefaultIfaceOpenBsd()

Determine the default interface on OpenBSD using the route command.

DefaultIfaceRouteCommand()

Determine default interface using the route -n command.

DefaultIfaceRouteGetCommand()

Determine default interface using the route get default command on BSD-based platforms, including Darwin (MacOS).

FcntlIface()

Uses fcntl.ioctl() to get the MAC address of a network interface on Linux (including WSL).

GetmacExe()

Uses Windows-builtin getmac.exe to get a interface's MAC address.

IfconfigEther()

Determine interface MAC using ifconfig command on Darwin (MacOS) systems.

IfconfigOther()

Wild 'Shot in the Dark' attempt at using ifconfig to get interface MAC on unknown platforms.

IfconfigWithIfaceArg()

ifconfig command with the interface name as an argument (e.g. ifconfig eth0) to determine MAC address of an interface.

IpLinkIface()

Determines interface MAC using the ip link command.

IpNeighborShow()

Uses the ip neighbor show command to get the MAC address of a remote host.

IpconfigExe()

Uses ipconfig.exe to find interface MAC addresses on Windows.

LanscanIface()

Uses the lanscan command to get the MAC address of a network interface on HP-UX.

Method()

Base class defining a method to get a MAC address.

NetstatIface()

Determines interface MAC using the netstat command.

SysIfaceFile()

Uses the contents of /sys/class/net/<iface>/address to get the MAC address of a interface.

WmicExe()

Use wmic.exe on Windows to find the MAC address of a network interface.

getmac.variables Module

Global variables, constants, and settings for the getmac package.

Classes

Constants()

Platform identifiers and other constants.

Settings()

User-configurable settings.

Variables()

Things that can change.

getmac.utils Module

Utility and helper functions. These are basic in functionality and should be relatively standalone. They are intended for internal use by getmac.

Functions

call_proc(executable, args)

Wrapper around subprocess.check_output() with some logging and type conversion.

check_command(command)

Check if a command exists using shutil.which().

check_path(filepath)

Check if the file pointed to by filepath exists and is readable.

clean_mac(mac)

Check and format a string result to be lowercase colon-separated MAC.

fetch_ip_using_dns()

Determine the IP address of the default network interface.

popen(command, args)

Execute a command with arguments and return the stdout (stderr is discarded).

read_file(filepath)

Open and read a file.

search(regex, text[, group_index, flags])

Search for a regular expression in a string, and return the specified group.