Skip to main content

Working with network MAC addresses

Project description

macaddr

As a network engineer you many have to deal with MAC address values. In some cases a network operating system wants the MAC address in a particular format. The following are common formats:

* aa:bb:cc:dd:ee:ff
* aabb-ccdd-eeff
* aabb.ccdd.eeff

As well as their upper-case variants, AA:BB:CC:DD:EE:FF for example.

This package provides the MacAddress class definition and a supporting format method that allows you to develop programs using a MAC address in different formats.

Installation

pip install macaddr

Usage

By default the MacAddress is formated in the "2 byte colon separated" format.

from macaddr import MacAddress

mac = MacAddress("aabb.ccdd.eeff")
print(mac)
aa:bb:cc:dd:ee:ff

You can obtain differnt formats using the format method.

from macaddr import MacAddress

mac = MacAddress("aabb.ccdd.eeff")
print(mac.format(size=4, sep='-', to_case=str.upper))
AABB-CCDD-EEFF

The format method values are cached so that repeated calls to format with the same arguments return the cached value. For example, if you had a network of 1000 devices, 500 of them required the "2-colon" format and 500 of them required the "4-dot" format, then these two formats are only computed twice.

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

macaddr-2.1.tar.gz (7.5 kB view hashes)

Uploaded Source

Built Distribution

macaddr-2.1-py3-none-any.whl (7.5 kB view hashes)

Uploaded Python 3

Supported by

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