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

# Package ip

Routines for IPv4 and IPv6 addresses, subnets and ranges.

Submodules | [hide private]
netaddr.ip.glob: Routines for IP glob-style address ranges. netaddr.ip.iana: Routines for accessing data published by IANA (Internet Assigned Numbers Authority). netaddr.ip.intset: Immutable integer set type. netaddr.ip.rfc1924: A basic implementation of RFC 1924 ;-) netaddr.ip.sets: Set based operations for IP addresses and subnets.

Classes | [hide private]
| BaseIP An abstract base class for common operations shared between various IP related subclasses.
| IPAddress An individual IPv4 or IPv6 address without a net mask or subnet prefix.
| IPNetwork An IPv4 or IPv6 network or subnet.
| IPRange An arbitrary IPv4 or IPv6 address range.

Functions | [hide private]
iter_unique_ips(*args) Returns: A generator that flattens out IP subnets, yielding unique individual IP addresses (no duplicates). |
cidr_abbrev_to_verbose(abbrev_cidr) A function that converts abbreviated IPv4 CIDRs to their more verbose equivalent. |
cidr_merge(ip_addrs) A function that accepts an iterable sequence of IP addresses and subnets merging them into the smallest possible list of CIDRs. |
cidr_exclude(target, exclude) Removes an exclude IP address or subnet from target IP subnet. |
spanning_cidr(ip_addrs) Function that accepts a sequence of IP addresses and subnets returning a single IPNetwork subnet that is large enough to span the lower and upper bound IP addresses with a possible overlap on either end. |
iter_iprange(start, end, step=1) An xrange work-alike generator for IP addresses. |
iprange_to_cidrs(start, end) A function that accepts an arbitrary start and end IP address or subnet and returns a list of CIDR subnets that fit exactly between the boundaries of the two with no overlap. |
smallest_matching_cidr(ip, cidrs) Matches an IP address or subnet against a given sequence of IP addresses and subnets. |
largest_matching_cidr(ip, cidrs) Matches an IP address or subnet against a given sequence of IP addresses and subnets. |
all_matching_cidrs(ip, cidrs) Matches an IP address or subnet against a given sequence of IP addresses and subnets. |

Variables | [hide private]
| IPV4_LOOPBACK = `IPNetwork('127.0.0.0/8')`
| IPV4_PRIVATE = ``(`IPNetwork('10.0.0.0/8')`,` IPNetwork('172.16.0.0`...``
| IPV4_LINK_LOCAL = `IPNetwork('169.254.0.0/16')`
| IPV4_MULTICAST = `IPNetwork('224.0.0.0/4')`
| IPV4_6TO4 = `IPNetwork('192.88.99.0/24')`
| IPV4_RESERVED = ``(`IPNetwork('39.0.0.0/8')`,` IPNetwork('128.0.0.0`...``
| IPV6_LOOPBACK = `IPAddress('::1')`
| IPV6_PRIVATE = ``(`IPNetwork('fc00::/7')`,` IPNetwork('fec0::/10')`)``
| IPV6_LINK_LOCAL = `IPNetwork('fe80::/10')`
| IPV6_MULTICAST = `IPNetwork('ff00::/8')`
| IPV6_RESERVED = ``(`IPNetwork('ff00::/12')`,` IPNetwork('::/8')`,` IP`...``

Function Details | [hide private]

### iter_unique_ips(*args) |
Parameters: `args` - A list of IP addresses and subnets passed in as arguments. Returns: A generator that flattens out IP subnets, yielding unique individual IP addresses (no duplicates).

### cidr_abbrev_to_verbose(abbrev_cidr) |
  - A function that converts abbreviated IPv4 CIDRs to their more verbose equivalent. Parameters: `abbrev_cidr` - an abbreviated CIDR. Uses the old-style classful IP address rules to decide on a default subnet prefix if one is not explicitly provided. Only supports IPv4 addresses. Examples :
           10                  - 10.0.0.0/8
           10/16               - 10.0.0.0/16
           128                 - 128.0.0.0/16
           128/8               - 128.0.0.0/8
           192.168             - 192.168.0.0/16
Returns: A verbose CIDR from an abbreviated CIDR or old-style classful network address, The original value if it was not recognised as a supported abbreviation.

### cidr_merge(ip_addrs) |
A function that accepts an iterable sequence of IP addresses and subnets merging them into the smallest possible list of CIDRs. It merges adjacent subnets where possible and removes duplicates. Parameters: `ip_addrs` - an iterable sequence of IP addresses and subnets. Returns: a summarized list of IPNetwork objects.

### cidr_exclude(target, exclude) |
Removes an exclude IP address or subnet from target IP subnet. Parameters: `target` - the target IP address or subnet to be divided up. `exclude` - the IP address or subnet to be removed from target. Returns: list of IPNetwork objects remaining after exclusion.

### spanning_cidr(ip_addrs) |
Function that accepts a sequence of IP addresses and subnets returning a single IPNetwork subnet that is large enough to span the lower and upper bound IP addresses with a possible overlap on either end. Parameters: `ip_addrs` - sequence of IP addresses and subnets. Returns: a single spanning IPNetwork subnet.

### iter_iprange(start, end, step=1) |
An xrange work-alike generator for IP addresses. It produces sequences based on start and stop IP address values, in intervals of step size. Parameters: `start` - start IP address. `end` - end IP address. `step` - (optional) size of step between IP addresses. Default: 1 Returns: an iterator of one or more IPAddress objects.

### iprange_to_cidrs(start, end) |
A function that accepts an arbitrary start and end IP address or subnet and returns a list of CIDR subnets that fit exactly between the boundaries of the two with no overlap. Parameters: `start` - the start IP address or subnet. `end` - the end IP address or subnet. Returns: a list of one or more IP addresses and subnets.

### smallest_matching_cidr(ip, cidrs) |
Matches an IP address or subnet against a given sequence of IP addresses and subnets. Parameters: `ip` - a single IP address or subnet. `cidrs` - a sequence of IP addresses and/or subnets. Returns: the smallest (most specific) matching IPAddress or IPNetwork object from the provided sequence, None if there was no match.

### largest_matching_cidr(ip, cidrs) |
Matches an IP address or subnet against a given sequence of IP addresses and subnets. Parameters: `ip` - a single IP address or subnet. `cidrs` - a sequence of IP addresses and/or subnets. Returns: the largest (least specific) matching IPAddress or IPNetwork object from the provided sequence, None if there was no match.

### all_matching_cidrs(ip, cidrs) |
Matches an IP address or subnet against a given sequence of IP addresses and subnets. Parameters: `ip` - a single IP address or subnet. `cidrs` - a sequence of IP addresses and/or subnets. Returns: all matching IPAddress and/or IPNetwork objects from the provided sequence, an empty list if there was no match.

Variables Details | [hide private]

  ### IPV4_PRIVATE Value:
      (IPNetwork('10.0.0.0/8'),
       IPNetwork('172.16.0.0/12'),
       IPNetwork('192.0.2.0/24'),
       IPNetwork('192.168.0.0/16'),
       IPRange('239.0.0.0', '239.255.255.255'))

  ### IPV4_RESERVED Value:
      (IPNetwork('39.0.0.0/8'),
       IPNetwork('128.0.0.0/16'),
       IPNetwork('191.255.0.0/16'),
       IPNetwork('192.0.0.0/24'),
       IPNetwork('223.255.255.0/24'),
       IPNetwork('240.0.0.0/4'),
       IPRange('234.0.0.0', '238.255.255.255'),
       IPRange('225.0.0.0', '231.255.255.255'))

  ### IPV6_RESERVED Value:
      (IPNetwork('ff00::/12'),
       IPNetwork('::/8'),
       IPNetwork('100::/8'),
       IPNetwork('200::/7'),
       IPNetwork('400::/6'),
       IPNetwork('800::/5'),
       IPNetwork('1000::/4'),
       IPNetwork('4000::/3'),
      ...