API¶
Full API reference for the getmac package.
In short: most people only need get_mac_address(), and maybe get_default_interface() and settings. Those three are the public API. The rest of this page is internal, and can change between releases.
Public API¶
These are the names in __all__ that you can import from getmac. settings is the one instance of Settings, see Configuration. (consts and gvars are internal, see below.) __version__ is the version string.
Functions¶
Get the name of the default network interface on the system. |
|
|
Get a MAC address from a local interface or remote host. |
Variables¶
User-configurable settings. |
Methods and lookup functions¶
Method is the base class of every method, and the built-in methods, the caches (METHODS, METHOD_CACHE and FALLBACK_CACHE), and the lower-level lookup functions are all here. Platforms lists the methods for each platform and lookup type, in the order they’re tried. How methods are chosen and used explains how one is selected.
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().
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="fe80::1")
host_mac = get_mac_address(hostname="home.router")
updated_mac = get_mac_address(ip="10.0.0.1", network_request=True)
Functions¶
|
Query for a MAC using a specific method. |
|
Get the cached instance of a named |
|
|
|
Initialize the method cache for the given method type. |
Classes¶
|
Query the Windows ARP table using |
|
Use the contents of |
Use the |
|
Use the |
|
Use the |
|
Use |
|
Uses |
|
Use |
|
Determine the default interface on FreeBSD using the |
|
Determine the default interface using the |
|
Determine the default interface by parsing the |
|
Use |
|
Determine the default interface on OpenBSD using the |
|
Determine default interface using the |
|
Determine default interface using the |
|
Use the |
|
Uses |
|
Uses Windows-builtin |
|
Determine interface MAC using |
|
Wild 'Shot in the Dark' attempt at using |
|
|
|
Determines interface MAC using the |
|
Uses the |
|
Uses |
|
Uses the |
|
|
Base class defining a method to get a MAC address. |
Use the |
|
Use |
|
Determines interface MAC using the |
|
Use |
|
Uses the contents of |
|
|
Use |
Variables¶
The methods that passed their test but weren't chosen as the primary method, in the order they appear in |
|
All of the methods getmac knows about, in the order they're tried. |
|
Primary method to use for a given method type |
Internals¶
Warning
Most of what this page describes lives in getmac.getmac and is an internal API that may change between releases. Use it with care.
getmac.variables and getmac.utils are internal and may change between releases. They’re documented because the methods use them, and because Customizing methods at runtime imports from them.
Global variables, constants, and settings for the getmac package.
Classes¶
Platform identifiers and other constants. |
|
|
User-configurable settings. |
Things that can change. |
Utility and helper functions. These are basic in functionality and should be relatively standalone. They are intended for internal use by getmac.
Functions¶
|
Wrapper around |
|
Check if a command exists using |
|
Check if the file pointed to by |
|
Check and format a string result to be lowercase colon-separated MAC. |
Determine the IP address of the default network interface. |
|
|
Execute a command with arguments and return the stdout (stderr is discarded). |
|
Open and read a file. |
|
Search for a regular expression in a string, and return the specified group. |