macaddress package¶
macaddress.macaddress module¶
This module includes MediaAccessControlAddress and AddressError.
-
exception
macaddress.macaddress.
AddressError
[source]¶ Bases:
Exception
MediaAccessControlAddress raises AddressError if instantiated with an invalid argument.
Parameters: message (str) – A human-readable error message.
-
class
macaddress.macaddress.
MediaAccessControlAddress
(address)[source]¶ Bases:
macaddress.ei48.ExtendedIdentifier48
MediaAccessControlAddress makes it easy to work with media access control (MAC) addresses.
-
is_broadcast
¶ Whether the MAC address is a broadcast address.
“ffffffffffff” = broadcast.
Type: bool
-
is_multicast
¶ Whether the MAC address is a multicast address (layer-two multicast, not layer-three multicast).
The least-significant bit in the first octet of a MAC address determines whether it is a multicast or a unicast.
1 = multicast.
Type: bool
-
is_unicast
¶ Whether the MAC address is a unicast address.
The least-significant bit in the first octet of a MAC address determines whether it is a multicast or a unicast.
0 = unicast.
Type: bool
-
is_uaa
¶ Whether the MAC address is a universally-administered address (UAA).
The second-least-significant bit in the first octet of a MAC address determines whether it is a UAA or an LAA.
0 = UAA.
Type: bool
-
is_laa
¶ Whether the MAC address is a locally-administered address (LAA).
The second-least-significant bit in the first octet of a MAC address determines whether it is a UAA or an LAA.
1 = LAA.
Type: bool
-
macaddress.ei48 module¶
This module includes ExtendedIdentifier48 and IdentifierError.
-
exception
macaddress.ei48.
IdentifierError
[source]¶ Bases:
Exception
ExtendedIdentifier48 raises IdentifierError if instantiated with an invalid argument.
Parameters: message (str) – A human-readable error message.
-
class
macaddress.ei48.
ExtendedIdentifier48
(identifier)[source]¶ Bases:
object
ExtendedIdentifier48 makes it easy to work with the IEEE’s 48-bit extended unique identifiers (EUI) and extended local identifiers (ELI).
The first 24 or 36 bits of an EUI is called an organizationally- unique identifier (OUI), while the first 24 or 36 bits of an ELI is called a company ID (CID).
Visit the IEEE’s website for more information on EUIs and ELIs.
Helpful link: https://standards.ieee.org/products-services/regauth/tut/index.html
-
original
¶ The hexadecimal identifier passed in by the user.
Type: str
-
normalized
¶ The hexadecimal identifier after replacing all uppercase letters with lowercase letters and removing all hypens, colons, and dots.
For example, if the user passes in A0-B1-C2-D3-E4-F5, then ExtendedIdentifier48 will return a0b1c2d3e4f5.
Type: str
-
is_valid
¶ Whether the user passed in a valid hexadecimal identifier.
Type: bool
-
octets
¶ Each of the hexadecimal identifier’s six octets.
Type: list
-
type
¶ The hexadecimal identifier’s type, where type is unique, local, or unknown.
The two least-significant bits in the first octet of an extended identifier determine whether it is an EUI.
00 = unique.
The four least-signficant bits in the first octet of an extended identifier determine whether it is an ELI.
1010 = local.
Type: str
-
has_oui
¶ Whether the hexadecimal identifier has an OUI.
If the identifier is an EUI, then it has an OUI.
Type: bool
-
has_cid
¶ Whether the hexadecimal identifier has a CID.
If the identifier is an ELI, then it has a CID.
Type: bool
-
decimal
¶ The decimal equivalent of the hexadecimal digits passed in by the user.
For example, if the user passes in A0-B1-C2-D3-E4-F5, then ExtendedIdentifier48 will return 176685338322165.
Type: int
-
binary
¶ The binary equivalent of the hexadecimal identifier passed in by the user. The most-significant digit of each octet appears first.
For example, if the user passes in A0-B1-C2-D3-E4-F5, then ExtendedIdentifier48 will return 101000001011000111000010110100111110010011110101.
Type: str
-
reverse_binary
¶ The reverse-binary equivalent of the hexadecimal identifier passed in by the user. The least-significant digit of each octet appears first.
For example, if the user passes in A0-B1-C2-D3-E4-F5, then ExtendedIdentifier48 will return 000001011000110101000011110010110010011110101111.
Type: str
Parameters: identifier (str) – Twelve hexadecimal digits (0-9, A-F, or a-f). Raises: IdentifierError
-
to_fragments
(bits=24)[source]¶ Returns the hexadecimal identifier’s two “fragments.”
For an EUI, this means the 24- or 36-bit OUI as the first fragment and the remaining device- or object-specific bits as the second fragment.
For an ELI, this means the 24- or 36-bit CID as the first fragment and the remaining device- or object-specific bits as the second fragment.
For example, if the user passes in A0-B1-C2-D3-E4-F5 and calls this method with either bits=24 or no keyword argument, then ExtendedIdentifier48 will return (a0b1c2, d3e4f5).
If the user passes in A0-B1-C2-D3-E4-F5 and calls this method with bits=36, then ExtendedIdentifier48 will return (a0b1c2d3e, 4f5).
Parameters: bits (int) – The number of bits for the OUI or CID.
The default value is 24.
-
to_plain_notation
()[source]¶ Returns the hexadecimal identifier in plain notation (for example, a0b1c2d3e4f5).
-
to_hyphen_notation
()[source]¶ Returns the hexadecimal identifier in hyphen notation (for example, a0-b1-c2-d3-e4-f5).
-
macaddress.octet module¶
This module includes Octet and OctetError.
-
exception
macaddress.octet.
OctetError
[source]¶ Bases:
Exception
Octet raises OctetError if instantiated with an invalid argument.
Parameters: message (str) – A human-readable error message.
-
class
macaddress.octet.
Octet
(digits)[source]¶ Bases:
object
Octet makes it easy to convert two hexadecimal digits to eight binary or reverse-binary digits.
This is useful when working with the IEEE’s extended unique identifiers and extended local identifiers.
-
original
¶ The hexadecimal digits passed in by the user.
Type: str
-
normalized
¶ The hexadecimal digits after replacing all uppercase letters with lowercase letters.
For example, if the user passes in A0, then Octet will return a0.
Type: str
-
is_valid
¶ Whether the user passed in valid hexadecimal digits.
Type: bool
-
decimal
¶ The decimal equivalent of the hexadecimal digits passed in by the user.
For example, if the user passes in A0, then Octet will return 160.
Type: int
-
binary
¶ The binary equivalent of the hexadecimal digits passed in by the user. The most-significant digit appears first.
For example, if the user passes in A0, then Octet will return 10100000.
Type: str
-
reverse_binary
¶ The reverse-binary equivalent of the hexadecimal digits passed in by the user. The least-significant digit appears first.
For example, if the user passes in A0, then Octet will return 00000101.
Type: str
Parameters: digits (str) – Two hexadecimal digits (0-9, A-F, or a-f). Raises: OctetError
-
Module contents¶
The macaddress library makes it easy to work with media access control (MAC) addresses.
-
class
macaddress.
ExtendedIdentifier48
(identifier)[source]¶ Bases:
object
ExtendedIdentifier48 makes it easy to work with the IEEE’s 48-bit extended unique identifiers (EUI) and extended local identifiers (ELI).
The first 24 or 36 bits of an EUI is called an organizationally- unique identifier (OUI), while the first 24 or 36 bits of an ELI is called a company ID (CID).
Visit the IEEE’s website for more information on EUIs and ELIs.
Helpful link: https://standards.ieee.org/products-services/regauth/tut/index.html
-
original
¶ The hexadecimal identifier passed in by the user.
Type: str
-
normalized
¶ The hexadecimal identifier after replacing all uppercase letters with lowercase letters and removing all hypens, colons, and dots.
For example, if the user passes in A0-B1-C2-D3-E4-F5, then ExtendedIdentifier48 will return a0b1c2d3e4f5.
Type: str
-
is_valid
¶ Whether the user passed in a valid hexadecimal identifier.
Type: bool
-
octets
¶ Each of the hexadecimal identifier’s six octets.
Type: list
-
type
¶ The hexadecimal identifier’s type, where type is unique, local, or unknown.
The two least-significant bits in the first octet of an extended identifier determine whether it is an EUI.
00 = unique.
The four least-signficant bits in the first octet of an extended identifier determine whether it is an ELI.
1010 = local.
Type: str
-
has_oui
¶ Whether the hexadecimal identifier has an OUI.
If the identifier is an EUI, then it has an OUI.
Type: bool
-
has_cid
¶ Whether the hexadecimal identifier has a CID.
If the identifier is an ELI, then it has a CID.
Type: bool
-
decimal
¶ The decimal equivalent of the hexadecimal digits passed in by the user.
For example, if the user passes in A0-B1-C2-D3-E4-F5, then ExtendedIdentifier48 will return 176685338322165.
Type: int
-
binary
¶ The binary equivalent of the hexadecimal identifier passed in by the user. The most-significant digit of each octet appears first.
For example, if the user passes in A0-B1-C2-D3-E4-F5, then ExtendedIdentifier48 will return 101000001011000111000010110100111110010011110101.
Type: str
-
reverse_binary
¶ The reverse-binary equivalent of the hexadecimal identifier passed in by the user. The least-significant digit of each octet appears first.
For example, if the user passes in A0-B1-C2-D3-E4-F5, then ExtendedIdentifier48 will return 000001011000110101000011110010110010011110101111.
Type: str
Parameters: identifier (str) – Twelve hexadecimal digits (0-9, A-F, or a-f). Raises: IdentifierError
-
to_fragments
(bits=24)[source]¶ Returns the hexadecimal identifier’s two “fragments.”
For an EUI, this means the 24- or 36-bit OUI as the first fragment and the remaining device- or object-specific bits as the second fragment.
For an ELI, this means the 24- or 36-bit CID as the first fragment and the remaining device- or object-specific bits as the second fragment.
For example, if the user passes in A0-B1-C2-D3-E4-F5 and calls this method with either bits=24 or no keyword argument, then ExtendedIdentifier48 will return (a0b1c2, d3e4f5).
If the user passes in A0-B1-C2-D3-E4-F5 and calls this method with bits=36, then ExtendedIdentifier48 will return (a0b1c2d3e, 4f5).
Parameters: bits (int) – The number of bits for the OUI or CID.
The default value is 24.
-
to_plain_notation
()[source]¶ Returns the hexadecimal identifier in plain notation (for example, a0b1c2d3e4f5).
-
to_hyphen_notation
()[source]¶ Returns the hexadecimal identifier in hyphen notation (for example, a0-b1-c2-d3-e4-f5).
-
-
class
macaddress.
MediaAccessControlAddress
(address)[source]¶ Bases:
macaddress.ei48.ExtendedIdentifier48
MediaAccessControlAddress makes it easy to work with media access control (MAC) addresses.
-
is_broadcast
¶ Whether the MAC address is a broadcast address.
“ffffffffffff” = broadcast.
Type: bool
-
is_multicast
¶ Whether the MAC address is a multicast address (layer-two multicast, not layer-three multicast).
The least-significant bit in the first octet of a MAC address determines whether it is a multicast or a unicast.
1 = multicast.
Type: bool
-
is_unicast
¶ Whether the MAC address is a unicast address.
The least-significant bit in the first octet of a MAC address determines whether it is a multicast or a unicast.
0 = unicast.
Type: bool
-
is_uaa
¶ Whether the MAC address is a universally-administered address (UAA).
The second-least-significant bit in the first octet of a MAC address determines whether it is a UAA or an LAA.
0 = UAA.
Type: bool
-
is_laa
¶ Whether the MAC address is a locally-administered address (LAA).
The second-least-significant bit in the first octet of a MAC address determines whether it is a UAA or an LAA.
1 = LAA.
Type: bool
-
-
class
macaddress.
Octet
(digits)[source]¶ Bases:
object
Octet makes it easy to convert two hexadecimal digits to eight binary or reverse-binary digits.
This is useful when working with the IEEE’s extended unique identifiers and extended local identifiers.
-
original
¶ The hexadecimal digits passed in by the user.
Type: str
-
normalized
¶ The hexadecimal digits after replacing all uppercase letters with lowercase letters.
For example, if the user passes in A0, then Octet will return a0.
Type: str
-
is_valid
¶ Whether the user passed in valid hexadecimal digits.
Type: bool
-
decimal
¶ The decimal equivalent of the hexadecimal digits passed in by the user.
For example, if the user passes in A0, then Octet will return 160.
Type: int
-
binary
¶ The binary equivalent of the hexadecimal digits passed in by the user. The most-significant digit appears first.
For example, if the user passes in A0, then Octet will return 10100000.
Type: str
-
reverse_binary
¶ The reverse-binary equivalent of the hexadecimal digits passed in by the user. The least-significant digit appears first.
For example, if the user passes in A0, then Octet will return 00000101.
Type: str
Parameters: digits (str) – Two hexadecimal digits (0-9, A-F, or a-f). Raises: OctetError
-
-
exception
macaddress.
IdentifierError
[source]¶ Bases:
Exception
ExtendedIdentifier48 raises IdentifierError if instantiated with an invalid argument.
Parameters: message (str) – A human-readable error message.