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

Class CIDR

source code

object --+    
         |    
 AddrRange --+
             |
            CIDR

A block of contiguous IPv4 or IPv6 network addresses defined by a base network address and a bitmask prefix or subnet mask address indicating the size/extent of the subnet.

This class does not accept any non zero bits to be set right of the bitmask (unlike the IP class which is less strict). Doing so raises an AddrFormatError exception.

Examples of supported formats :-

  1. CIDR address format - <address>/<mask_length>:
       192.168.0.0/16
    
  2. Address and subnet mask combo :
       192.168.0.0/255.255.0.0 == 192.168.0.0/16
    
  3. Partial or abbreviated formats. Prefixes may be omitted and in this case old classful default prefixes apply :
       10          ==  10.0.0.0/8
       10.0        ==  10.0.0.0/8
       10/8        ==  10.0.0.0/8
    
       128         ==  128.0.0.0/16
       128.0       ==  128.0.0.0/16
       128/16      ==  128.0.0.0/16
    
       192         ==  10.0.0.0/24
       192.168.0   ==  192.168.0.0/24
       192.168/16  ==  192.168.0.0/16
    
Instance Methods
 
__init__(self, addr_mask, klass=<class 'netaddr.address.IP'>)
Constructor.
source code
 
netmask(self)
Returns: The subnet mask address of this CIDR range.
source code
 
hostmask(self)
Returns: The host mask address of this CIDR range.
source code
 
prefixlen(self)
Returns: Size of mask (in bits) of this CIDR range.
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
 
wildcard(self)
Returns: A Wildcard object equivalent to this CIDR.
source code

Inherited from AddrRange: __contains__, __eq__, __ge__, __getitem__, __gt__, __iter__, __le__, __len__, __lt__, __ne__, __setattr__, first, last, size

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

Properties

Inherited from object: __class__

Method Details

__init__(self, addr_mask, klass=<class 'netaddr.address.IP'>)
(Constructor)

source code 

Constructor.

Parameters:
  • addr_mask - a valid IPv4/IPv6 CIDR address or abbreviated IPv4 network address
  • klass - (optional) type, BIF or class used to create each object returned. Default: IP class. See nrange() documentations for additional details on options.
Overrides: object.__init__

netmask(self)

source code 
Returns:
The subnet mask address of this CIDR range.

hostmask(self)

source code 
Returns:
The host mask address of this CIDR range.

prefixlen(self)

source code 
Returns:
Size of mask (in bits) of this CIDR range.

__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__

wildcard(self)

source code 
Returns:
A Wildcard object equivalent to this CIDR.
  • If CIDR was initialised with klass=str a wildcard string is returned, in all other cases a Wildcard object is returned.
  • Only supports IPv4 CIDR addresses.