Skip to main content

MAC Address-focused library similar to ipaddress

Project description

MacTools

MacTools is a MAC-centric library for aiding in network handling and automation.

Full test coverage and fully type annoted.

Installation

This is a publicly available library on PyPI and can be installed with:

pip install mactools

Features

MacAddress

MAC object similar to Python's ipaddress library. Performs validation on creation and allows quick and easy format changing for the user. Accepts EUI-48 and EUI-64 formats.

Usage

Built-in MacAddress attributes allow for conversion between the common formats of either delimiters, decimal, or binary. Such as:

from mactools import MacAddress
mac = MacAddress('00:11:22:AA:BB:CC')

# returns the MAC without an delimiters or spaces (001122AABBCC)
mac.clean

# returns the MAC with period delimiters (0011.22AA.BBCC)
mac.period

# returns the decimal/numeric form (73596058572)
mac.decimal

# returns the OUI (00:11:22)
mac.oui

The full format list includes: clean, colon, period, hyphen, space, oui, decimal, binary

IPv6 Support

This library has some methods for simplifying IPv6 SLAAC-based address creation:

# returns the IPv6 Suffix/Interface ID in EUI-64 per RFC 4291 (0211:22ff:feaa:bbcc)
mac.eui64_suffix

# returns the Link-local address (fe80::0211:22ff:feaa:bbcc)
mac.link_local_address

# returns a Global Unicast Address (2001:db8::) as `ipaddress.IPv6Address`
mac.get_global_address('2001:db8::0211:22ff:feaa:bbcc')

OUICache

Local cache of the IEEE OUI MA-L, MA-M, and MA-S registries for quick look-ups without needing to consistently hit API endpoints for individual queries.

MacAddress currently automatically performs the look-up on creation.

The full information is available, including OUI, Vendor, Address, etc.

The cache also contains specific references to commonly defined non-vendor OUIs such as Multicast, IEEE protocols (STP, LLDP, etc), Locally administered and others.

Usage

Intakes a string MAC/OUI or MacAddress object for either vendor or full record from the IEEE OUI MA-L registry. The cache will be built if one is not present (or if manually prompted) or the version of the code has changed.

from mactools import get_oui_cache

# the `mac` defined above already has the look-up performed and recorded on creation, if the record was found

vendor = mac.vendor

cache = get_oui_cache()
oui = '01000C'

# These methods would also work with the `mac` defined above as well 
vendor = cache.get_vendor(oui)

vendor will be the string of vendor registered to IEEE. It will also identify common protocol MACs (such as Spanning Tree, Cisco/Extreme, etc.) and randomized MACs (locally administered).

License

This project is under the MIT license (see the LICENSE file for full text).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mactools-1.8.0.tar.gz (1.7 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mactools-1.8.0-py3-none-any.whl (1.7 MB view details)

Uploaded Python 3

File details

Details for the file mactools-1.8.0.tar.gz.

File metadata

  • Download URL: mactools-1.8.0.tar.gz
  • Upload date:
  • Size: 1.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.8

File hashes

Hashes for mactools-1.8.0.tar.gz
Algorithm Hash digest
SHA256 1d3ae306367d49ddd52b264bfe46edd04f3a7d9620e304d420c59d7d4721e8bf
MD5 b0d99a2904f0475852fd8ec174ce021e
BLAKE2b-256 841246dccc9b226f62e8dd2a1bd46d1f9fb106b847215a8e6326b67ac20fa6c6

See more details on using hashes here.

File details

Details for the file mactools-1.8.0-py3-none-any.whl.

File metadata

  • Download URL: mactools-1.8.0-py3-none-any.whl
  • Upload date:
  • Size: 1.7 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.8

File hashes

Hashes for mactools-1.8.0-py3-none-any.whl
Algorithm Hash digest
SHA256 229af2e15c2be69cc16a5867363f9792e3903d92707943f7710e37220ab26918
MD5 997a1c2abfc37101d3b1e76e44067668
BLAKE2b-256 97ccfee0569e13984c43029b4c5cdb92b9a0dc20afffb9707832487dab5e6835

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page