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

Class Wildcard

source code

object --+    
         |    
   IPRange --+
             |
            Wildcard

Represents blocks of IPv4 addresses using a wildcard or glob style syntax.

Individual octets can be represented using the following shortcuts :

  1. * - the asterisk octet (represents values 0 through 255)
  2. 'x-y' - the hyphenated octet (represents values x through y)

A few basic rules also apply :

  1. x must always be greater than y, therefore :
  2. only one hyphenated octet per wildcard is allowed
  3. only asterisks are permitted after a hyphenated octet

Example wildcards :

   '192.168.0.1'       #   a single address
   '192.168.0.0-31'    #   32 addresses
   '192.168.0.*'       #   256 addresses
   '192.168.0-1.*'     #   512 addresses
   '192.168-169.*.*'   #   131,072 addresses
   '*.*.*.*'           #   the whole IPv4 address space

Aside

Wildcard ranges are not directly equivalent to CIDR blocks as they can represent address ranges that do not fall on strict bit mask boundaries. They are very suitable in configuration files being more obvious and readable than their CIDR equivalents, especially for admins and users without much networking knowledge or experience.

All CIDR blocks can always be represented as wildcard ranges but the reverse is not true. Wildcards are almost but not quite as flexible as IPRange objects.

Instance Methods [hide private]
 
__init__(self, wildcard, fmt=<class 'netaddr.address.IP'>)
Constructor.
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__

    Inherited from IPRange
 
__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
 
__ge__(self, other)
Returns: True if the boundaries of this range are greater or equal to other, False otherwise.
source code
 
__getitem__(self, index)
Returns: The IP address(es) in this address range referenced by index/slice.
source code
 
__gt__(self, other)
Returns: True if the boundaries of this range are greater than other, False otherwise.
source code
 
__hash__(self)
Returns: The hash of this address range.
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
 
__iter__(self)
Returns: An iterator object providing access to all network addresses within this range.
source code
 
__le__(self, other)
Returns: True if the boundaries of this range are less or equal to other, False otherwise.
source code
 
__len__(self)
Returns: The total number of network addresses in this range.
source code
 
__lt__(self, other)
Returns: True if the boundaries of this range are less than 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
 
adjacent(self, other)
Returns: True if other's boundary touches the boundary of this address range, False otherwise.
source code
 
cidrs(self)
Returns: A list of one or more CIDR objects covering this address 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
 
iprange(self)
Returns: A valid IPRange object for this address range.
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
 
overlaps(self, other)
Returns: True if other's boundary crosses the boundary of this address range, False otherwise.
source code
 
size(self)
Returns: The total number of network addresses in this 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
 
wildcard(self)
Returns: A Wildcard object equivalent to this CIDR.
source code
Static Methods [hide private]
 
is_valid(wildcard)
A static method that validates wildcard address ranges.
source code
Class Variables [hide private]
  STRATEGIES = (IPv4Strategy(32, 8, '.', 4, 10))
  ADDR_TYPES = (0, 4)
  strategy = StrategyDescriptor(STRATEGIES)
  addr_type = AddrTypeDescriptor(ADDR_TYPES)
  fmt = FormatDescriptor(IP)
    Inherited from IPRange
  first = AddrValueDescriptor('first')
  last = AddrValueDescriptor('last')
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

is_valid(wildcard)
Static Method

source code 

A static method that validates wildcard address ranges.

Parameters:
  • wildcard - an IPv4 wildcard address.
Returns:
True if wildcard address is valid, False otherwise.

__init__(self, wildcard, fmt=<class 'netaddr.address.IP'>)
(Constructor)

source code 

Constructor.

Parameters:
  • wildcard - a valid IPv4 wildcard address
  • fmt - (optional) callable used on return values. Default: IP objects. See nrange() documentations for more details on the various options..
Overrides: object.__init__

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