Package netaddr :: Module address :: Class IPRange |
[hide private]
[frames] | no frames]

# Class IPRange

source code

    object --+
             |
            IPRange

Known Subclasses:
  - CIDR
  - , Wildcard

Represents arbitrary contiguous blocks of IPv4 and IPv6 addresses using only a lower and upper bound IP address.

It is the base class for more specialised block types such as CIDR() and Wildcard(). There is no requirement that the boundary IP addresses fall on strict bitmask boundaries.

The sort order for sequence of mixed version IPRange objects is IPv4 followed by IPv6, based on the range's magnitude (size).

Instance Methods | [hide private]
__init__(self, first, last, fmt=<class 'netaddr.address.IP'>) Constructor. | source code
__hash__(self) Returns: The hash of this address range. | source code
tuple(self) Returns: A 3-element tuple (first, last, addr_type) which represent the basic details of this IPRange object. | 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
format(self, int_addr, fmt=None) Returns: a network address in the format returned after passing it through this object's fmt property callable. | source code
__getitem__(self, index) Returns: The IP address(es) in this address range referenced 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: `False` if the boundaries of this range are the same as other, `True` 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
iprange(self) Returns: A valid IPRange object for this address range. | source code
cidrs(self) Returns: A list of one or more CIDR objects covering this address range. | source code
wildcard(self) Returns: A Wildcard object equivalent to this CIDR. | source code
issubnet(self, other) Returns: True if other's boundary is equal to or within this range. | source code
issupernet(self, other) Returns: True if other's boundary is equal to or contains this range. | source code
adjacent(self, other) Returns: True if other's boundary touches the boundary of this address range, False otherwise. | source code
overlaps(self, other) Returns: True if other's boundary crosses the boundary of this address range, False otherwise. | source code
__str__(self) str(x) | source code
__repr__(self) Returns: executable Python string to recreate equivalent object. | source code
Inherited from `object`: `__delattr__`, `__getattribute__`, `__new__`, `__reduce__`, `__reduce_ex__`, `__setattr__`

Class Variables | [hide private]
| STRATEGIES = `ST_IPV4, ST_IPV6`
| ADDR_TYPES = ``(`0`,` 4`,` 6`)``
| strategy = `StrategyDescriptor(STRATEGIES)`
| addr_type = `AddrTypeDescriptor(ADDR_TYPES)`
| first = `AddrValueDescriptor('first')`
| last = `AddrValueDescriptor('last')`
| fmt = `FormatDescriptor(IP)`

Properties | [hide private]
Inherited from `object`: `__class__`

Method Details | [hide private]

### __init__(self, first, last, fmt=<class 'netaddr.address.IP'>) (Constructor) | source code
Constructor. Parameters: `first` - start address for this IP address range. `last` - stop address for this IP address range. `fmt` - (optional) callable used to create return values. Default: IP() objects. See nrange() documentations for more details on the various 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__

### tuple(self) | source code
Returns: A 3-element tuple (first, last, addr_type) which represent the basic details of this IPRange object.

### __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 potentially exceeds `2^31` addresses.

### format(self, int_addr, fmt=None) | source code
Parameters: `int_addr` - a network address as an unsigned integer. `fmt` - (optional) a callable used on return values. Default: None. If set to None, this method uses the self.fmt setting instead. The argument is provided as an override option. Returns: a network address in the format returned after passing it through this object's fmt property callable.

### __getitem__(self, index) (Indexing operator) | source code
Returns: The IP address(es) in this address range referenced by index/slice. Slicing objects can produce large sequences so generator objects are returned instead of a list. Wrapping a slice with `list()` or `tuple()` may be required dependent on context in which it is called.

### __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` - and IP/IPRange class/subclass instance or IP string value 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: `False` if the boundaries of this range are the same as other, `True` 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. Raises IndexError if the result exceeds address range maximum.

### __isub__(self, i) | source code
Decrements start and end addresses of this range by the current size. Raises IndexError if the result is less than zero.

### iprange(self) | source code
Returns: A valid IPRange object for this address range.

### cidrs(self) | source code
Returns: A list of one or more CIDR objects covering this address range. Please Note: a list is returned even if this range maps to a single CIDR because arbitrary ranges may not be aligned with base 2 subnet sizes and will therefore return multiple CIDRs.

### wildcard(self) | source code
Returns: A Wildcard object equivalent to this CIDR. If CIDR was initialised with `fmt=str`, a wildcard string is returned, in all other cases a Wildcard object is returned. Only supports IPv4 CIDR addresses.

### issubnet(self, other) | source code
Returns: True if other's boundary is equal to or within this range. False otherwise.

### issupernet(self, other) | source code
Returns: True if other's boundary is equal to or contains this range. False otherwise.

### adjacent(self, other) | source code
Returns: True if other's boundary touches the boundary of this address range, False otherwise.

### overlaps(self, other) | source code
Returns: True if other's boundary crosses the boundary of this address range, False otherwise.

### __str__(self) (Informal representation operator) | source code
str(x) Overrides: object.__str__ (inherited documentation)

### __repr__(self) (Representation operator) | source code
repr(x) Returns: executable Python string to recreate equivalent object. Overrides: object.__repr__