noc.core.mac

Module Contents

noc.core.mac.rx_mac_address_cisco
noc.core.mac.rx_mac_address_cisco_media
noc.core.mac.rx_mac_address_sixblock
noc.core.mac.rx_mac_address_hp
noc.core.mac.rx_mac_address_solid
class noc.core.mac.MAC

Bases: str

MAC address validation and conversion class

>>> MAC("1234.5678.9ABC")
'12:34:56:78:9A:BC'
>>> MAC("1234.5678.9abc")
'12:34:56:78:9A:BC'
>>> MAC("0112.3456.789a.bc")
'12:34:56:78:9A:BC'
>>> MAC("1234.5678.9abc.def0")
Traceback (most recent call last):
    ...
ValueError: Invalid MAC: '1234.5678.9abc.def0'
>>> MAC("12:34:56:78:9A:BC")
'12:34:56:78:9A:BC'
>>> MAC("12-34-56-78-9A-BC")
'12:34:56:78:9A:BC'
>>> MAC("0:13:46:50:87:5")
'00:13:46:50:87:05'
>>> MAC("123456-789abc")
'12:34:56:78:9A:BC'
>>> MAC("12-34-56-78-9A-BC-DE")   #doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
    ...
ValueError: Invalid MAC: '12:34:56:78:9A:BC:DE'
>>> MAC("AB-CD-EF-GH-HJ-KL")   #doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
    ...
ValueError: Invalid MAC: 'AB:CD:EF:GH:HJ:KL'
>>> MAC("aabb-ccdd-eeff")
'AA:BB:CC:DD:EE:FF'
>>> MAC("aabbccddeeff")
'AA:BB:CC:DD:EE:FF'
>>> MAC("AABBCCDDEEFF")
'AA:BB:CC:DD:EE:FF'
>>> MAC(0xAABBCCDDEEFF)
'AA:BB:CC:DD:EE:FF'
>>> MAC("AABBCCDDEEFF") + " -- " + MAC("0011.2233.4455")
'AA:BB:CC:DD:EE:FF -- 00:11:22:33:44:55'
is_multicast

Check if MAC address is multicast one :return: True if MAC is multicast

classmethod __new__(cls, mac)
__long__(self)
__int__(self)
classmethod _clean(cls, mac)
to_cisco(self)

Convert to Cisco-like format

>>> MAC("AA:BB:CC:DD:EE:FF").to_cisco()
'aabb.ccdd.eeff'
shift(self, count)

Return shifted MAC address

>>> MAC("AA:BB:CC:DD:EE:FF").shift(0)
'AA:BB:CC:DD:EE:FF'
>>> MAC("AA:BB:CC:DD:EE:FF").shift(1)
'AA:BB:CC:DD:EF:00'
>>> MAC("AA:BB:CC:DD:EE:FF").shift(256)
'AA:BB:CC:DD:EF:FF'
>>> MAC("AA:BB:CC:DD:EE:FF").shift(257)
'AA:BB:CC:DD:F0:00'
>>> MAC("AA:BB:CC:DD:EE:FF").shift(4096)
'AA:BB:CC:DD:FE:FF'
Parameters:count
Returns: