Using macaddress

While macaddress contains multiple classes, the only one with which you need to interact directly is MediaAccessControlAddress.

Import MediaAccessControlAddress.

>>> from macaddress import MediaAccessControlAddress

Instantiate MediaAccessControlAddress by passing in a MAC address in plain, hyphen, colon, or dot notation.

>>> mac = MediaAccessControlAddress("a0b1c2d3e4f5")
>>> mac = MediaAccessControlAddress("a0-b1-c2-d3-e4-f5")
>>> mac = MediaAccessControlAddress("a0:b1:c2:d3:e4:f5")
>>> mac = MediaAccessControlAddress("a0b1.c2d3.e4f5")

To determine whether the MAC address is a broadcast, a multicast (layer-two), or a unicast address, access its is_broadcast, is_multicast, and is_unicast properties.

>>> print(mac.is_broadcast)
False
>>> print(mac.is_multicast)
False
>>> print(mac.is_unicast)
True

To determine whether the MAC address is a universally-administered address (UAA) or a locally-administered address (LAA), access its is_uaa and is_laa properties.

>>> print(mac.is_uaa)
True
>>> print(mac.is_laa)
False

To work with the MAC address’s octets, access its octets property, which contains six Octet objects.

>>> print(mac.octets)
[Octet('a0'), Octet('b1'), Octet('c2'), Octet('d3'), Octet('e4'), Octet('f5')]

To determine whether the MAC address is an extended unique identifier (EUI), an extended local identifier (ELI), or unknown, access its type property.

>>> print(mac.type)
unique

To determine whether the MAC address has an organizationally-unique identifier (OUI) or a company ID (CID), access its has_oui and has_cid properties.

>>> print(mac.has_oui)
True
>>> print(mac.has_cid)
False

To view the decimal equivalent of the MAC address, access its decimal property.

>>> print(mac.decimal)
176685338322165

To view the binary equivalent of the MAC address, access its binary and reverse_binary properties. With binary, the most-significant digit of each octet appears first. With reverse_binary, the least-significant digit of each octet appears first.

>>> print(mac.binary)
101000001011000111000010110100111110010011110101
>>> print(mac.reverse_binary)
000001011000110101000011110010110010011110101111

To return the MAC address’s two “fragments,” call the to_fragments method. For an EUI, this means the 24-bit OUI as the first fragment and the remaining interface-specific bits as the second fragment. For an ELI, this means the 24-bit CID as the first fragment and the remaining interface-specific bits as the second fragment.

>>> fragments = mac.to_fragments()
>>> print(fragments)
('a0b1c2', 'd3e4f5')

To return the MAC address in different notations, call the to_plain_notation, to_hyphen_notation, to_colon_notation, and to_dot_notation methods.

>>> plain = mac.to_plain_notation()
>>> print(plain)
a0b1c2d3e4f5
>>> hyphen = mac.to_hyphen_notation()
>>> print(hyphen)
a0-b1-c2-d3-e4-f5
>>> colon = mac.to_colon_notation()
>>> print(colon)
a0:b1:c2:d3:e4:f5
>>> dot = mac.to_dot_notation()
>>> print(dot)
a0b1.c2d3.e4f5