Skip to content

jeremyschulman/macaddr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

For working with MAC address values

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages