Package netaddr :: Package ip :: Module glob
[hide private]
[frames] | no frames]

Module glob

Routines for IP glob-style address ranges.

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 IP glob is allowed
  3. only asterisks are permitted after a hyphenated octet

Example IP globs :

   '192.0.2.1'       #   a single address
   '192.0.2.0-31'    #   32 addresses
   '192.0.2.*'       #   256 addresses
   '192.0.2-3.*'     #   512 addresses
   '192.0-1.*.*'   #   131,072 addresses
   '*.*.*.*'           #   the whole IPv4 address space

Aside

IP glob ranges are not directly equivalent to CIDR blocks. They can represent address ranges that do not fall on strict bit mask boundaries. They are suitable for use in configuration files, being more obvious and readable than their CIDR counterparts, especially for admins and end users with little or no networking knowledge or experience.

All CIDR addresses can always be represented as IP globs but the reverse is not always true.

Classes [hide private]
  IPGlob
Represents an IP address range using a glob-style syntax (x.x.x-y.*).
Functions [hide private]
 
valid_glob(ipglob)
Returns: True if IP range glob is valid, False otherwise.
 
glob_to_iptuple(ipglob)
A function that accepts a glob-style IP range and returns the component lower and upper bound IP address.
 
glob_to_iprange(ipglob)
A function that accepts a glob-style IP range and returns the equivalent IP range.
 
iprange_to_globs(start, end)
A function that accepts an arbitrary start and end IP address or subnet and returns one or more glob-style IP ranges.
 
glob_to_cidrs(ipglob)
A function that accepts a glob-style IP range and returns a list of one or more IP CIDRs that exactly matches it.
 
cidr_to_glob(cidr)
A function that accepts an IP subnet in a glob-style format and returns a list of CIDR subnets that exactly matches the specified glob.
Variables [hide private]
  __package__ = 'netaddr.ip'
Function Details [hide private]

valid_glob(ipglob)

 
Parameters:
  • ipglob - An IP address range in a glob-style format.
Returns:
True if IP range glob is valid, False otherwise.

glob_to_iptuple(ipglob)

 

A function that accepts a glob-style IP range and returns the component lower and upper bound IP address.

Parameters:
  • ipglob - an IP address range in a glob-style format.
Returns:
a tuple contain lower and upper bound IP objects.

glob_to_iprange(ipglob)

 

A function that accepts a glob-style IP range and returns the equivalent IP range.

Parameters:
  • ipglob - an IP address range in a glob-style format.
Returns:
an IPRange object.

iprange_to_globs(start, end)

 

A function that accepts an arbitrary start and end IP address or subnet and returns one or more glob-style IP ranges.

Parameters:
  • start - the start IP address or subnet.
  • end - the end IP address or subnet.
Returns:
a list containing one or more IP globs.

glob_to_cidrs(ipglob)

 

A function that accepts a glob-style IP range and returns a list of one or more IP CIDRs that exactly matches it.

Parameters:
  • ipglob - an IP address range in a glob-style format.
Returns:
a list of one or more IP objects.

cidr_to_glob(cidr)

 

A function that accepts an IP subnet in a glob-style format and returns a list of CIDR subnets that exactly matches the specified glob.

Parameters:
  • cidr - an IP object CIDR subnet.
Returns:
a list of one or more IP addresses and subnets.