getmac - Man Page


getmac ā€” Cross-platform Python package to get MAC addresses Latest version on PyPI Documentation status Travis CI build status Appveyor build status

Get the MAC address of remote LAN hosts and system network interfaces using Python.

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

It provides one function: get_mac_address()



Python 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="")
ip6_mac = get_mac_address(ip6="::1")
host_mac = get_mac_address(hostname="localhost")
updated_mac = get_mac_address(ip="", network_request=True)

# Enabling debugging
from getmac import getmac
getmac.DEBUG = 2  # DEBUG level 2
print(getmac.get_mac_address(interface="Ethernet 3"))

# Changing the port used for updating ARP table (UDP packet)
from getmac import getmac
getmac.PORT = 44444  # Default: 55555
print(get_mac_address(ip="", network_request=True))

Terminal Examples

getmac --help
getmac --version

# No arguments will return MAC of the default interface.
python -m getmac

# Interface names, IPv4/IPv6 addresses, or Hostnames can be specified
getmac --interface ens33
getmac --ip
getmac --ip6 ::1
getmac --hostname home.router

# Running as a Python module with shorthands for the arguments
python -m getmac -i 'Ethernet 4'
python -m getmac -4
python -m getmac -6 ::1
python -m getmac -n home.router

# Getting the MAC address of a remote host obviously requires
# the ARP table to be populated. By default, getmac will do
# this for you by sending a small UDP packet to a high port (55555)
# If you don't want this to happen, you can disable it.
# This is useful if you're 100% certain the ARP table will be
# populated already, or in red team/forensic scenarios.
getmac --no-network-request -4
python -m getmac --no-network-request -n home.router

# Debug levels can be specified with '-d'
getmac --debug
python -m getmac -d -i enp11s4
python -m getmac -dd -n home.router

Note: the terminal interface will not work on Python 2.6 and older (Sorry RHEL 6 users!).



Docker Examples

Run getmac container and provide flags

docker run -it ghostofgoes/getmac:latest --help
docker run -it ghostofgoes/getmac:latest --version
docker run -it ghostofgoes/getmac:latest -n localhost

There is a pre-built container located on the Docker hub. Alternatively, you can build the image yourself (from the repository root directory):

docker build . -t getmac

All or almost all features should work on "supported" platforms (OSes).

All sub-versions are the latest available on your platform (with the exception of 2.6).

Please report any problems by opening a issue on GitHub!


Known Issues

Contributors are more than welcome! See the contribution guide to get started, and checkout the todo list for a full list of tasks and bugs.

Before submitting a PR, please make sure you've completed the pull request checklist!

The Python Discord server is a good place to ask questions or discuss the project (Handle: @KnownError).


Many of the methods used to acquire an address and the core logic framework are attributed to the CPython project's UUID implementation.

Other Notable Sources

MIT. Feel free to copy, modify, and use to your heart's content. Enjoy :)


Christopher Goes


Oct 06, 2018 0.6.0