Package netaddr :: Module address :: Class AddrRange
[frames] | no frames]

Class AddrRange

source code

object --+
         |
        AddrRange
Known Subclasses:

A block of contiguous network addresses bounded by an arbitrary start and stop address. There is no requirement that they fall on strict bit mask boundaries, unlike CIDR addresses.

This is the only network address aggregate supporting all network address types. Most AddrRange subclasses usually only support a subset of address types.

A sequence of address ranges sort first by address type then by magnitude. So for a list containing ranges of all currently supported address types, IPv4 ranges come first, then IPv6, EUI-48 and lastly EUI-64.

Instance Methods
 
__init__(self, first, last, klass=<class 'netaddr.address.Addr'>)
Constructor.
source code
 
__hash__(self)
Returns: The hash of this address range.
source code
 
__len__(self)
Returns: The total number of network addresses in this range.
source code
 
size(self)
Returns: The total number of network addresses in this range.
source code
 
data_flavour(self, int_addr)
Returns: a network address in whatever 'flavour' is required based on the value of the klass property.
source code
 
__getitem__(self, index)
Returns: The network address(es) in this address range indicated by index/slice.
source code
 
__iter__(self)
Returns: An iterator object providing access to all network addresses within this range.
source code
 
__contains__(self, addr)
Returns: True if given address or range falls within this range, False otherwise.
source code
 
__eq__(self, other)
Returns: True if the boundaries of this range are the same as other, False otherwise.
source code
 
__ne__(self, other)
Returns: True if the boundaries of this range are not the same as other, False otherwise.
source code
 
__lt__(self, other)
Returns: True if the boundaries of this range are less than other, False otherwise.
source code
 
__le__(self, other)
Returns: True if the boundaries of this range are less or equal to other, False otherwise.
source code
 
__gt__(self, other)
Returns: True if the boundaries of this range are greater than other, False otherwise.
source code
 
__ge__(self, other)
Returns: True if the boundaries of this range are greater or equal to other, False otherwise.
source code
 
__iadd__(self, i)
Increments start and end addresses of this range by the current size.
source code
 
__isub__(self, i)
Decrements start and end addresses of this range by the current size.
source code
 
__str__(self)
str(x)
source code
 
__repr__(self)
Returns: An executable Python statement that can recreate an object with an equivalent state.
source code

Inherited from object: __delattr__, __getattribute__, __new__, __reduce__, __reduce_ex__, __setattr__

Class Variables
  STRATEGIES = (netaddr.address.IPv4StrategyOpt(32, 8, '.', 4, F...
  ADDR_TYPES = (0, 4, 6, 48, 64)
  strategy = StrategyDescriptor(STRATEGIES)
  addr_type = AddrTypeDescriptor(ADDR_TYPES)
  first = AddrValueDescriptor('first')
  last = AddrValueDescriptor('last')
  klass = KlassDescriptor(Addr)
Properties

Inherited from object: __class__

Method Details

__init__(self, first, last, klass=<class 'netaddr.address.Addr'>)
(Constructor)

source code 

Constructor.

Parameters:
  • first - start address for this network address range.
  • last - stop address for this network address range.
  • klass - (optional) class used to create each object returned. Default: Addr() objects. See nrange() documentations for additional details on options.
Overrides: object.__init__

__hash__(self)
(Hashing function)

source code 

hash(x)

Returns:
The hash of this address range. Allow them to be used in sets and as keys in dictionaries.
Overrides: object.__hash__

__len__(self)
(Length operator)

source code 
Returns:
The total number of network addresses in this range.
  • Use this method only for ranges that contain less than 2^31 addresses or try the size() method. Raises an IndexError if size is exceeded.

size(self)

source code 
Returns:
The total number of network addresses in this range.
  • Use this method in preference to __len__() when size of ranges exceeds 2^31 addresses.

data_flavour(self, int_addr)

source code 
Parameters:
  • int_addr - an network address as a network byte order integer.
Returns:
a network address in whatever 'flavour' is required based on the value of the klass property.

__getitem__(self, index)
(Indexing operator)

source code 
Returns:
The network address(es) in this address range indicated by index/slice. Slicing objects can produce large sequences so generator objects are returned instead to the usual sequences. Wrapping a raw slice with list() or tuple() may be required dependent on context.

__iter__(self)

source code 
Returns:
An iterator object providing access to all network addresses within this range.

__contains__(self, addr)
(In operator)

source code 
Parameters:
  • addr - object of Addr/AddrRange (sub)class or a network address string to be compared.
Returns:
True if given address or range falls within this range, False otherwise.

__eq__(self, other)
(Equality operator)

source code 
Parameters:
  • other - an address object of the same address type as self.
Returns:
True if the boundaries of this range are the same as other, False otherwise.

__ne__(self, other)

source code 
Parameters:
  • other - an address object of the same address type as self.
Returns:
True if the boundaries of this range are not the same as other, False otherwise.

__lt__(self, other)
(Less-than operator)

source code 
Parameters:
  • other - an address object of the same address type as self.
Returns:
True if the boundaries of this range are less than other, False otherwise.

__le__(self, other)
(Less-than-or-equals operator)

source code 
Parameters:
  • other - an address object of the same address type as self.
Returns:
True if the boundaries of this range are less or equal to other, False otherwise.

__gt__(self, other)
(Greater-than operator)

source code 
Parameters:
  • other - an address object of the same address type as self.
Returns:
True if the boundaries of this range are greater than other, False otherwise.

__ge__(self, other)
(Greater-than-or-equals operator)

source code 
Parameters:
  • other - an address object of the same address type as self.
Returns:
True if the boundaries of this range are greater or equal to other, False otherwise.

__iadd__(self, i)

source code 

Increments start and end addresses of this range by the current size.

If the result exceeds address type range for the address type an IndexError is raised.

__isub__(self, i)

source code 

Decrements start and end addresses of this range by the current size.

If the result less than zero an IndexError is raised.

__str__(self)
(Informal representation operator)

source code 

str(x)

Overrides: object.__str__
(inherited documentation)

__repr__(self)
(Representation operator)

source code 

repr(x)

Returns:
An executable Python statement that can recreate an object with an equivalent state.
Overrides: object.__repr__

Class Variable Details

STRATEGIES

Value:
(netaddr.address.IPv4StrategyOpt(32, 8, '.', 4, False, False),
 netaddr.address.IPv6Strategy(128, 16, ':', 6, True, False),
 netaddr.address.EUI48Strategy(48, 8, '-', 48, True, True),
 netaddr.address.AddrStrategy(64, 8, '-', 64, True, True))