getmac

0.9.5 · active · verified Wed Apr 15

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.

Warnings

Install

Imports

Quickstart

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}")

view raw JSON →