Package netaddr :: Module strategy :: Class EUI48Strategy |
[frames] | no frames]

# Class EUI48Strategy

source code

      object --+
               |
    AddrStrategy --+
                   |
                  EUI48Strategy

Implements the operations that can be performed on an IEEE 48-bit EUI (Extended Unique Identifer) a.k.a. a MAC (Media Access Control) layer 2 address.

Supports all common (and some less common MAC string formats including Cisco's 'triple hextet' format and also bare MACs that contain no delimiters.

Instance Methods
__init__(self, word_fmt=`'``%02x``'`, word_sep=`'``-``'`, uppercase=True) Constructor. | source code
reset(self) Resets the internal state of this strategy to safe default values. | source code
valid_str(self, addr) Returns: `True` if MAC address string is valid, `False` otherwise. | source code
str_to_int(self, addr) Returns: A network byte order integer that is equivalent to value represented by EUI-48/MAC string address. | source code
int_to_str(self, int_val, word_sep=None, word_fmt=None) Returns: A MAC address in string form that is equivalent to value represented by a network byte order integer. | source code
Inherited from `AddrStrategy`: `__repr__`, `bits_to_int`, `int_to_bin`, `int_to_bits`, `int_to_packed`, `int_to_words`, `packed_to_int`, `valid_bits`, `valid_int`, `valid_words`, `words_to_int` Inherited from `object`: `__delattr__`, `__getattribute__`, `__hash__`, `__new__`, `__reduce__`, `__reduce_ex__`, `__setattr__`, `__str__`

Class Variables
| RE_MAC_FORMATS = ``[`re.compile(r'`(?i)`^`(``[`0`-`9A`-`F`]``{1,2}``)`:`(``[`0`-`9A`-`F`]``{``...``
| _ = ``'``^([0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F``...``
Inherited from `AddrStrategy`: `STRUCT_FORMATS`

Properties
Inherited from `object`: `__class__`

Method Details

### __init__(self, word_fmt=`'``%02x``'`, word_sep=`'``-``'`, uppercase=True) (Constructor) | source code
Constructor. Parameters: `word_sep` - separator between each word. (Default: '-') `word_fmt` - format string for each hextet. (Default: '%02x') `uppercase` - return uppercase MAC/EUI-48 addresses. (Default: True) Overrides: object.__init__

### valid_str(self, addr) | source code
Parameters: `addr` - An EUI-48 or MAC address in string form. Returns: `True` if MAC address string is valid, `False` otherwise. Overrides: AddrStrategy.valid_str

### str_to_int(self, addr) | source code
Parameters: `addr` - An EUI-48 or MAC address in string form. Returns: A network byte order integer that is equivalent to value represented by EUI-48/MAC string address. Overrides: AddrStrategy.str_to_int

### int_to_str(self, int_val, word_sep=None, word_fmt=None) | source code
Parameters: `int_val` - A network byte order integer. `word_sep` - (optional) The separator used between words in an address string. `word_fmt` - (optional) A Python format string used to format each word of address. Returns: A MAC address in string form that is equivalent to value represented by a network byte order integer. Overrides: AddrStrategy.int_to_str

Class Variable Details

  ### RE_MAC_FORMATS Value:
      [re.compile(r'(?i)^([0-9A-F]{1,2}):([0-9A-F]{1,2}):([0-9A-F]{1,2}):([0
      -9A-F]{1,2}):([0-9A-F]{1,2}):([0-9A-F]{1,2})$'),
       re.compile(r'(?i)^([0-9A-F]{1,2})-([0-9A-F]{1,2})-([0-9A-F]{1,2})-([0
      -9A-F]{1,2})-([0-9A-F]{1,2})-([0-9A-F]{1,2})$'),
       re.compile(r'(?i)^([0-9A-F]{1,4}):([0-9A-F]{1,4}):([0-9A-F]{1,4})$'),
       re.compile(r'(?i)^([0-9A-F]{1,4})-([0-9A-F]{1,4})-([0-9A-F]{1,4})$'),
       re.compile(r'(?i)^([0-9A-F]{5,6})-([0-9A-F]{5,6})$'),
       re.compile(r'(?i)^([0-9A-F]{5,6}):([0-9A-F]{5,6})$'),
      ...

  ### _ Value:
      '^([0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-
      9A-F][0-9A-F][0-9A-F])$'