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

# Package netaddr

A Python library for manipulating IP and EUI network addresses.

Version: 0.7.1

Submodules | [hide private]
netaddr.core: Common code shared between various netaddr sub modules netaddr.eui: Classes and functions for dealing with MAC addresses, EUI-48, EUI-64, OUI, IAB identifiers. netaddr.eui.ieee: Provides access to public OUI and IAB registration data published by the IEEE. netaddr.fbsocket: Fallback routines for Python's standard library socket module netaddr.ip: Routines for IPv4 and IPv6 addresses, subnets and ranges. 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. netaddr.strategy: Shared logic for various address types. netaddr.strategy.eui48: IEEE 48-bit EUI (MAC address) logic. netaddr.strategy.eui64: IEEE 64-bit EUI (Extended Unique Indentifier) logic. netaddr.strategy.ipv4: IPv4 address logic. netaddr.strategy.ipv6: IPv6 address logic. netaddr.tests: Runs all netaddr unit tests. netaddr.tests.test

Classes | [hide private]
| AddrConversionError An Exception indicating a failure to convert between address types or notations.
| AddrFormatError An Exception indicating a network address is not correctly formatted.
| NotRegisteredError An Exception indicating that an OUI or IAB was not found in the IEEE Registry.
| 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.
| IPSet Represents an unordered collection (set) of unique IP addresses and subnets.
| IPGlob Represents an IP address range using a glob-style syntax (x.x.x-y.*).
| EUI An IEEE EUI (Extended Unique Identifier).
| IAB An individual IEEE IAB (Individual Address Block) identifier.
| OUI An individual IEEE OUI (Organisationally Unique Identifier).
| ipv6_compact An IPv6 dialect class - compact form.
| ipv6_full An IPv6 dialect class - 'all zeroes' form.
| ipv6_verbose An IPv6 dialect class - extra wide 'all zeroes' form.
| mac_eui48 A standard IEEE EUI-48 dialect class.
| mac_unix A UNIX-style MAC address dialect class.
| mac_cisco A Cisco 'triple hextet' MAC address dialect class.
| mac_bare A bare (no delimiters) MAC address dialect class.
| mac_pgsql A PostgreSQL style (2 x 24-bit words) MAC address dialect class.

Functions | [hide private]
all_matching_cidrs(ip, cidrs) Matches an IP address or subnet against a given sequence of IP addresses and subnets. |
cidr_abbrev_to_verbose(abbrev_cidr) A function that converts abbreviated IPv4 CIDRs to their more verbose equivalent. |
cidr_exclude(target, exclude) Removes an exclude IP address or subnet from target IP subnet. |
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. |
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. |
iter_iprange(start, end, step=1) An xrange work-alike generator for IP addresses. |
iter_unique_ips(*args) Returns: A generator that flattens out IP subnets, yielding unique individual IP addresses (no duplicates). |
largest_matching_cidr(ip, cidrs) Matches an IP address or subnet against a given sequence of IP addresses and subnets. |
smallest_matching_cidr(ip, cidrs) Matches an IP address or subnet against a given sequence of IP addresses and subnets. |
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. |
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. |
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. |
glob_to_iprange(ipglob) A function that accepts a glob-style IP range and returns the equivalent IP range. |
glob_to_iptuple(ipglob) A function that accepts a glob-style IP range and returns the component lower and upper bound IP address. |
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. |
valid_glob(ipglob) Returns: `True` if IP range glob is valid, `False` otherwise. |
base85_to_ipv6(addr) Convert a base 85 IPv6 address to its hexadecimal format. |
ipv6_to_base85(addr) Convert a regular IPv6 address to base 85. |
valid_ipv4(addr) Returns: `True` if IPv4 address is valid, `False` otherwise. |
valid_ipv6(addr) Returns: `True` if IPv6 address is valid, `False` otherwise. |
valid_mac(addr) Returns: `True` if MAC address string is valid, `False` otherwise. |

Function Details | [hide private]

### 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.

### 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_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.

### 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.

### 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.

### 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.

### 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).

### 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.

### 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.

### 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.

### 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.

### 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.

### 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.

### 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.

### 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.

### valid_glob(ipglob) |
Parameters: `ipglob` - An IP address range in a glob-style format. Returns: `True` if IP range glob is valid, `False` otherwise.

### valid_ipv4(addr) |
Parameters: `addr` - An IPv4 address in presentation (string) format. Returns: `True` if IPv4 address is valid, `False` otherwise.

### valid_ipv6(addr) |
Parameters: `addr` - An IPv6 address in presentation (string) format. Returns: `True` if IPv6 address is valid, `False` otherwise.

### valid_mac(addr) |
Parameters: `addr` - An IEEE EUI-48 (MAC) address in string form. Returns: `True` if MAC address string is valid, `False` otherwise.