Package netaddr :: Module address :: Class Wildcard
[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
 
__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 IPRange: __contains__, __eq__, __ge__, __getitem__, __gt__, __hash__, __iadd__, __isub__, __iter__, __le__, __len__, __lt__, __ne__, adjacent, cidrs, format, iprange, issubnet, issupernet, overlaps, size, wildcard

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

Static Methods
 
is_valid(wildcard)
A static method that validates wildcard address ranges.
source code
Class Variables
  STRATEGIES = (IPv4StrategyOpt(32, 8, '.', 4, 10, False))
  ADDR_TYPES = (0, 4)
  strategy = StrategyDescriptor(STRATEGIES)
  addr_type = AddrTypeDescriptor(ADDR_TYPES)
  fmt = FormatDescriptor(IP)

Inherited from IPRange: first, last

Properties

Inherited from object: __class__

Method Details

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__