Skip to main content
File added late

1 file was added to this release more than 14 days after its initial publication. Inspect the release files before installing.

Latest versionon PyPI Travis CI build status

Get the MAC address of remote hosts or network interfaces using Python.

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

  • System network interfaces (by interface name)
  • Remote hosts (by IPv4/IPv6 address or hostname)

It provides one function: get_mac_address()

Features

  • Pure-Python
  • Supports Python 2.6+, 3.2+, pypy, and pypy3
  • No dependencies
  • Small size
  • Can be used as an independant .py file
  • Simple terminal tool (when installed as a package)

Usage

In Python

.. code-block:: python

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)

Terminal

.. code-block:: bash

get-mac --interface 'eth0' get-mac --ip '192.168.0.1' get-mac --ip6 '::1'

Note: following will not work with python 2.6

python -m getmac --interface 'eth0' python -m getmac --ip '192.168.0.1'

get_mac_address()

  • interface: Name of a network interface on the system.
  • ip: IPv4 address of a remote host.
  • ip6: IPv6 address of a remote host.
  • hostname: Hostname of a remote host.
  • network_request: If an network request (ping usually) should be made to update and populate the ARP table of remote hosts used to lookup MACs in most circumstances. Disable this if you want to just use what's already in the table, or if you have requirements to prevent network traffic.

Notes

  • The first four arguments are mutually exclusive. network_request does not have any functionality when the interface argument is specified, and can be safely set if using in a script.
  • If none of the arguments are selected, the default network interface for the system will be used.
  • For the time being, it assumes you are using Ethernet.
  • Exceptions will be handled silently and returned as a None. If you run into problems, create an issue on GitHub, or set DEBUG to true if you're brave.
  • Messages are output using the warnings library. If you are using logging, they can be captured using logging.captureWarnings(). Otherwise, they can be suppressed using warnings.filterwarnings("ignore"). https://docs.python.org/3/library/warnings.html

Platforms

  • Windows
    • Versions: 2000, XP, Vista, 7, 8/8.1, 10
    • Commands: ipconfig, ping
    • Libraries: ctypes
  • Linux
    • Distros: Debian, RHEL
    • Commands: arp, ip, ifconfig
    • Libraries: fcntl
  • Mac OS X (Darwin)
    • Same linux/unix
  • HP-UX:
    • lanscan
  • Generic Unix-based
    • Commands: netstat, cat

Caveats & Known issues

Caveats

  • Depending on the platform, there could be a performance detriment, due to heavy usage of regular expressions.
  • Testing is only on a few platforms (Ubuntu 14+, Windows 10, OSX), so your mileage may vary. Please report any problems by opening a issue on GitHub!

Known Issues

  • Hostnames for IPv6 devices are not yet supported.
  • The "default" of selecting the default route interface for the platform currently attempts to use common default interfaces, not the actual default.

Sources

Many of the methods used to acquire an address and the core logic framework are attributed to the CPython project's UUID implementation. * https://github.com/python/cpython/blob/master/Lib/uuid.py * https://github.com/python/cpython/blob/2.7/Lib/uuid.py

Other sources are noted with inline comments at the appropriate sections.

TODO

  • Cache results on regex-heavy functions (add a arg to disable this behavior)
  • Decide on what the error behavior should be. Is returning None for both errors and simple failures to find acceptable?
  • New platforms
    • Android
    • FreeBSD
    • OpenBSD
    • Solaris
    • Windows pre-2000

License

MIT. Feel free to copy, modify, and use to your heart's content. Have fun!

Metadata

Release files for get-mac 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

File added late

1 file was uploaded more than 14 days after the first file in this release.

While project maintainers occasionally add legitimate files to an existing release, late additions can also indicate a security compromise.

We recommend inspecting the release files before installing.

Source distribution (sdist)

Source distribution for get-mac 0.2.1
File Size Uploaded
get-mac-0.2.1.tar.gz 9.0 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for get-mac 0.2.1
File Interpreter ABI Platform
get_mac-0.2.1-py3.6.egg Legacy Egg format - - Details
get_mac-0.2.1-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 35.4 kB

Release files / get-mac-0.2.1.tar.gz

Download URL get-mac-0.2.1.tar.gz
Size 9.0 kB
Tags Source
SHA-256 checksum
How to use checksums
5bfa0bbdfd7873ba98c31a1672e6702f97f1f77a251aaf0252a7b5b57070a844
BLAKE2b-256 checksum
How to use checksums
df9ea28d72c16ee482b3485ae6277b609cc8c5c8c980aff1a65dc3aa9648c4f8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / get_mac-0.2.1-py3.6.egg

File added late

This file was uploaded more than 14 days after the first file in this release.

While project maintainers occasionally add legitimate files to an existing release, late additions can also indicate a security compromise.

We recommend inspecting the release file before installing.

Download URL get_mac-0.2.1-py3.6.egg
Size 16.5 kB
Tags Egg
SHA-256 checksum
How to use checksums
7810cd9ad22b4911864baa5c4912c75d6314ca7dfc63c02fa4a445a14af65db7
BLAKE2b-256 checksum
How to use checksums
89ae535b4ac072f1f21ecebd3d78b6ec83f30723ee680e93ddda8dd9c8b7dd0b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/3.6.5

Release files / get_mac-0.2.1-py2.py3-none-any.whl

Download URL get_mac-0.2.1-py2.py3-none-any.whl
Size 9.9 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
dc05ec701b679311891ddb9511a065b8f940bfe83a8c86de0154b3a3c109a7b0
BLAKE2b-256 checksum
How to use checksums
f9edc7f65b7a535adb7c89c6ffa69a4d00efa259bdf5372685f141500ffc4b2e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page