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

Module address

source code

network address classes (IP, EUI) and associated aggregate classes (CIDR, Wildcard and IPRange).

Classes [hide private]
  AddrTypeDescriptor
A descriptor that checks addr_type property assignments for validity and also keeps the strategy property in sync with any changes made.
  AddrValueDescriptor
A descriptor that checks assignments to the named parameter passed to the constructor.
  StrategyDescriptor
A descriptor that checks strategy property assignments for validity and also keeps the addr_type property in sync with any changes made.
  PrefixLenDescriptor
A descriptor that checks prefixlen property assignments for validity based on address type.
  FormatDescriptor
A descriptor that checks formatter property assignments for validity.
  Addr
The base class containing common functionality for all subclasses representing various network address types.
  EUI
Represents an IEEE EUI (Extended Unique Identifier) indentifier.
  IP
Represents individual IPv4 and IPv6 addresses.
  IPRange
Represents arbitrary contiguous blocks of IPv4 and IPv6 addresses using only a lower and upper bound IP address.
  CIDR
Represents blocks of IPv4 and IPv6 addresses using CIDR (Classless Inter-Domain Routing) notation.
  Wildcard
Represents blocks of IPv4 addresses using a wildcard or glob style syntax.
  IPRangeSet
*EXPERIMENTAL* A customised Python set class that deals with collections of IPRange class and subclass instances.
Functions [hide private]
 
nrange(start, stop, step=1, fmt=None)
An xrange work alike generator that produces sequences of IP addresses based on start and stop addresses, in intervals of step size.
source code
 
cidr_to_bits(cidr)
Returns: a tuple containing CIDR in binary string format and addr_type.
source code
 
bits_to_cidr(bits, addr_type=0, fmt=None)
Returns: a CIDR object or string (determined by fmt).
source code
Variables [hide private]
  AT_STRATEGIES = {0: None, 4: IPv4Strategy(32, 8, '.', 4, 10), ...
Address type to strategy object lookup dict.
Function Details [hide private]

nrange(start, stop, step=1, fmt=None)

source code 

An xrange work alike generator that produces sequences of IP addresses based on start and stop addresses, in intervals of step size.

Parameters:
  • start - first IP address string or IP object in range.
  • stop - last IP address string or IP object in range
  • step - (optional) size of step between address in range. (Default: 1)
  • fmt - (optional) callable used on addresses returned. (Default: None - IP objects). Supported options :-
    • str - IP address in string format
    • int, long - IP address as an unsigned integer
    • hex - IP address as a hexadecimal number
    • IP class/subclass or callable that accepts addr_value and addr_type arguments.

cidr_to_bits(cidr)

source code 
Parameters:
  • cidr - a CIDR object or CIDR string value (acceptable by CIDR class constructor).
Returns:
a tuple containing CIDR in binary string format and addr_type.

bits_to_cidr(bits, addr_type=0, fmt=None)

source code 
Parameters:
  • bits - a CIDR in binary string format.
  • addr_type - (optional) CIDR address type (IP version). (Default: AT_UNSPEC - auto-select) If not specified AT_INET (IPv4) is assumed if length of binary string is <= /32. If binary string is > /32 and <= /128 AT_INET6 (IPv6) is assumed. Useful when you have IPv6 addresses with a prefixlen of /32 or less.
  • fmt - (optional) callable invoked on return CIDR. (Default: None - CIDR object). Also accepts str() and unicode().
Returns:
a CIDR object or string (determined by fmt).

Variables Details [hide private]

AT_STRATEGIES

Address type to strategy object lookup dict.

Value:
{0: None,
 4: IPv4Strategy(32, 8, '.', 4, 10),
 6: IPv6Strategy(128, 16, ':', 6, 16),
 48: EUI48Strategy(48, 8, '-', 48, 16),
 64: AddrStrategy(64, 8, '-', 64, 16)}