Registry / http-networking / getmac

getmac

JSON →
library0.9.5pypypi✓ verified 86d ago

getmac is a cross-platform Python library designed to reliably retrieve the MAC addresses of local network interfaces and remote hosts. The current version is 0.9.5, and it maintains a regular release cadence, providing minor updates with bug fixes and improvements every few months.

pip install getmac
INSTALL
IMPORT
SIG · GETMAC
G
getmac
http-networkingpythonv0.9.5
Install
1.5s avg
Import
65ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.9.5 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.063s · 17.9MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 1.5s · import 0.067s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

get_mac_address
from getmac import get_mac_address

Demonstrates how to retrieve the local machine's MAC address, and optionally, how to fetch the MAC address for a specific interface or a remote IP.

from getmac import get_mac_address # Get the MAC address of the first available local interface mac_address = get_mac_address() print(f"Local MAC Address: {mac_address}") # Optionally, get MAC for a specific interface (e.g., 'eth0' or 'en0') # interface_mac = get_mac_address(interface='eth0') # if interface_mac: # print(f"MAC for eth0: {interface_mac}") # Optionally, get MAC for a remote IP address (requires ARP access) # remote_ip = '192.168.1.1' # Replace with a reachable IP # remote_mac = get_mac_address(ip=remote_ip) # if remote_mac: # print(f"MAC for {remote_ip}: {remote_mac}")
getmac --version
Debug
Known issues
breakingCompatibility with Python versions 2.7, 3.4, 3.5, and 3.6 will be completely removed in `getmac` 1.0.0. If your project relies on these older Python environments, you must pin your `getmac` dependency to `<1.0.0` (e.g., `getmac~=0.9.0`) to prevent breakage upon upgrade.
fix
Upgrade to Python 3.7+ or pin `getmac<1.0.0` in your project's dependencies.
affects: <1.0.0
gotchaVersion 0.9.0 was a 'complete rewrite' of the library. While the public API aimed for backward compatibility, significant internal refactoring occurred. Users upgrading from versions prior to 0.9.0 should conduct thorough testing, as behavioral changes or differences in how MAC addresses are resolved in edge cases might occur.
fix
Review the 'docs/rewrite.md' (from the 0.9.0 release) for details on changes and thoroughly test your application after upgrading.
affects: <0.9.0
gotchaMAC address retrieval is highly dependent on the operating system, network configuration, and available system utilities. `getmac` has a history of fixing platform-specific issues (e.g., macOS ARP, BusyBox arping, IPv6 handling). Inconsistent or unexpected results may arise on certain OS/network environments; consider specifying `interface` or `ip` for more targeted queries and robust error handling.
fix
For critical applications, test `getmac` extensively across target platforms. Utilize `interface` or `ip` parameters to narrow down retrieval scope and implement retry logic or fallback mechanisms.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'getmac'
The 'getmac' library is not installed in the Python environment being used, or there's a mismatch between the Python interpreter running the script and where the package was installed.
fix
Install the library using pip: `pip install getmac` or `python -m pip install getmac`. If multiple Python versions are present, ensure you use the correct pip (e.g., `pip3 install getmac`).
get_mac_address() returns None
The `getmac` library could not reliably determine the MAC address for the specified interface, IP, or hostname due to various reasons such as network conditions, permissions, the host being unreachable, or specific platform limitations (e.g., VPNs, WSL, local interface IPs on Linux, or issues with ARP/NDP tables).
fix
Ensure the target host is reachable and on the local network. Try specifying a different interface, IP, or hostname. For remote hosts, ensure `network_request=True` is set (which is the default, but can be explicitly enabled). Check for relevant permissions if running on Linux/macOS. For persistent issues on Windows, ensure WMI is functioning correctly. If on Linux/WSL, be aware that getting the MAC of a local interface IP might not work.
ERROR: Invalid class (from Windows command line `getmac`)
This error typically occurs on Windows when the underlying `getmac.exe` utility (which the Python `getmac` library might interact with or emulate) encounters issues with Windows Management Instrumentation (WMI) services or lacks the necessary permissions to query network information.
fix
Ensure Windows Management Instrumentation (WMI) service is running and accessible. Check system permissions for the user running the command or Python script. Running the command prompt or script as an administrator might resolve permission-related `Invalid class` errors. Also, ensure the Windows installation itself is not corrupted.
NameError: name 'get_mac' is not defined
This error occurs when a user attempts to call a function named `get_mac` which does not exist in the `getmac` library. The correct function name is `get_mac_address`.
fix
Replace `get_mac(...)` with `get_mac_address(...)`. For example, instead of `from getmac import get_mac; mac = get_mac()`, use `from getmac import get_mac_address; mac = get_mac_address()`.
Upgrade
Version history
0.9.5latest on PyPI · released Jul 16, 2024
Audit
Dependencies

No dependency data recorded yet.

Agent activity
5 hits · last 30 days
node
4
Amazon
1
Resources
getmac — pip install getmac · libregistry