netaddr.ip.IPAddress

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

# Class IPAddress

    object --+
             |
        BaseIP --+
                 |
                IPAddress

An individual IPv4 or IPv6 address without a net mask or subnet prefix.

To support these and other network based operations, see IPNetwork.

Instance Methods | [hide private]
__init__(self, addr, version=None, flags=0) Constructor. |
__getstate__(self) Returns: Pickled state of an `IPAddress` object. |
__setstate__(self, state) |
is_hostmask(self) Returns: `True` if this IP address host mask, `False` otherwise. |
is_netmask(self) Returns: `True` if this IP address network mask, `False` otherwise. |
__iadd__(self, num) Increases the numerical value of this IPAddress by num. |
__isub__(self, num) Decreases the numerical value of this IPAddress by num. |
__add__(self, num) Add the numerical value of this IP address to num and provide the result as a new IPAddress object. |
__radd__(self, num) Add the numerical value of this IP address to num and provide the result as a new IPAddress object. |
__sub__(self, num) Subtract the numerical value of this IP address from num providing the result as a new IPAddress object. |
__rsub__(self, num) Subtract num (lvalue) from the numerical value of this IP address (rvalue) providing the result as a new IPAddress object. |
key(self) Returns: a key tuple that uniquely identifies this IP address. |
sort_key(self) Returns: A key tuple used to compare and sort this IPAddress correctly. |
__int__(self) Returns: the value of this IP address as an unsigned integer |
__long__(self) Returns: the value of this IP address as an unsigned integer |
__oct__(self) Returns: an octal string representation of this IP address. |
__hex__(self) Returns: a hexadecimal string representation of this IP address. |
__index__(self) Returns: return the integer value of this IP address when called by hex(), oct() or bin(). |
bits(self, word_sep=None) Returns: the value of this IP address as a binary digit string. |
ipv4(self) Returns: A numerically equivalent version 4 IPAddress object. |
ipv6(self, ipv4_compatible=False) Please Note: the IPv4-mapped IPv6 address format is now considered deprecated. |
format(self, dialect=None) Only relevant for IPv6 addresses. |
__or__(self, other) Returns: bitwise OR (x | y) between the integer value of this IP address and `other`. |
__and__(self, other) Returns: bitwise AND (x & y) between the integer value of this IP address and `other`. |
__xor__(self, other) Returns: bitwise exclusive OR (x ^ y) between the integer value of this IP address and `other`. |
__lshift__(self, numbits) Returns: an IPAddress object based on this one with its integer value left shifted by `numbits`. |
__rshift__(self, numbits) Returns: an IPAddress object based on this one with its integer value right shifted by `numbits`. |
__nonzero__(self) Returns: `True` if the numerical value of this IP address is not zero, `False` otherwise. |
__bool__(self) Returns: `True` if the numerical value of this IP address is not zero, `False` otherwise. |
__str__(self) Returns: IP address in presentational format |
__repr__(self) Returns: Python statement to create an equivalent object |
Inherited from `object`: `__delattr__`, `__format__`, `__getattribute__`, `__new__`, `__reduce__`, `__reduce_ex__`, `__setattr__`, `__sizeof__`, `__subclasshook__`
Inherited from BaseIP
__eq__(self, other) Returns: `True` if this IPAddress or IPNetwork object is equivalent to `other`, `False` otherwise. |
__ge__(self, other) Returns: `True` if this IPAddress or IPNetwork object is greater than or equal to `other`, `False` otherwise. |
__gt__(self, other) Returns: `True` if this IPAddress or IPNetwork object is greater than `other`, `False` otherwise. |
__hash__(self) Returns: A hash value uniquely indentifying this IP object. |
__le__(self, other) Returns: `True` if this IPAddress or IPNetwork object is less than or equal to `other`, `False` otherwise. |
__lt__(self, other) Returns: `True` if this IPAddress or IPNetwork object is less than `other`, `False` otherwise. |
__ne__(self, other) Returns: `True` if this IPAddress or IPNetwork object is not equivalent to `other`, `False` otherwise. |
_set_value(self, value) |
is_ipv4_compat(self) Returns: `True` if this IP is IPv4-mapped IPv6 address, `False` otherwise. |
is_ipv4_mapped(self) Returns: `True` if this IP is IPv4-compatible IPv6 address, `False` otherwise. |
is_link_local(self) Returns: `True` if this IP is link-local address `False` otherwise. |
is_loopback(self) Returns: `True` if this IP is loopback address (not for network transmission), `False` otherwise. |
is_multicast(self) Returns: `True` if this IP is multicast, `False` otherwise |
is_private(self) Returns: `True` if this IP is for internal/private use only (i.e. |
is_reserved(self) Returns: `True` if this IP is in IANA reserved range, `False` otherwise. |
is_unicast(self) Returns: `True` if this IP is unicast, `False` otherwise |

Properties | [hide private]
| packed The value of this IP address as a packed binary string.
| words A list of unsigned integer words (octets for IPv4, hextets for IPv6) found in this IP address.
| bin The value of this IP adddress in standard Python binary representational form (0bxxx).
| reverse_dns The reverse DNS lookup record for this IP address
Inherited from `object`: `__class__`
Inherited from BaseIP
| _module
| _value
| info A record dict containing IANA registration details for this IP address if available, None otherwise.
| value a positive integer representing the value of IP address/subnet.
| version the IP protocol version represented by this IP object.

Method Details | [hide private]

### __init__(self, addr, version=None, flags=0) (Constructor) |
Constructor. Parameters: `addr` - an IPv4 or IPv6 address which may be represented in an accepted string format, as an unsigned integer or as another IPAddress object (copy construction). `version` - (optional) optimizes version detection if specified and distinguishes between IPv4 and IPv6 for addresses with an equivalent integer value. `flags` - (optional) decides which rules are applied to the interpretation of the addr value. Supported constants are INET_PTON and ZEROFILL. See the netaddr.core docs for further details. Overrides: object.__init__

### __getstate__(self) |
Returns: Pickled state of an `IPAddress` object.

### __setstate__(self, state) |
Parameters: `state` - data used to unpickle a pickled `IPAddress` object.

### is_hostmask(self) |
Returns: `True` if this IP address host mask, `False` otherwise.

### is_netmask(self) |
Returns: `True` if this IP address network mask, `False` otherwise.

### __iadd__(self, num) |
Increases the numerical value of this IPAddress by num. Parameters: `num` - size of IP address increment. An IndexError is raised if result exceeds maximum IP address value or is less than zero.

### __isub__(self, num) |
Decreases the numerical value of this IPAddress by num. Parameters: `num` - size of IP address decrement. An IndexError is raised if result is less than zero or exceeds maximum IP address value.

### __add__(self, num) (Addition operator) |
Add the numerical value of this IP address to num and provide the result as a new IPAddress object. Parameters: `num` - size of IP address increase. Returns: a new IPAddress object with its numerical value increased by num.

### __radd__(self, num) (Right-side addition operator) |
Add the numerical value of this IP address to num and provide the result as a new IPAddress object. Parameters: `num` - size of IP address increase. Returns: a new IPAddress object with its numerical value increased by num.

### __sub__(self, num) (Subtraction operator) |
Subtract the numerical value of this IP address from num providing the result as a new IPAddress object. Parameters: `num` - size of IP address decrease. Returns: a new IPAddress object with its numerical value decreased by num.

### __rsub__(self, num) |
Subtract num (lvalue) from the numerical value of this IP address (rvalue) providing the result as a new IPAddress object. Parameters: `num` - size of IP address decrease. Returns: a new IPAddress object with its numerical value decreased by num.

### key(self) |
Returns: a key tuple that uniquely identifies this IP address. Overrides: BaseIP.key

### sort_key(self) |
Returns: A key tuple used to compare and sort this IPAddress correctly. Overrides: BaseIP.sort_key

### __int__(self) |
Returns: the value of this IP address as an unsigned integer

### __long__(self) |
Returns: the value of this IP address as an unsigned integer

### __oct__(self) |
Returns: an octal string representation of this IP address.

### __hex__(self) |
Returns: a hexadecimal string representation of this IP address.

### __index__(self) |
Returns: return the integer value of this IP address when called by hex(), oct() or bin().

### bits(self, word_sep=None) |
Parameters: `word_sep` - (optional) the separator to insert between words. Default: None - use default separator for address type. Returns: the value of this IP address as a binary digit string.

### ipv4(self) |
Returns: A numerically equivalent version 4 IPAddress object. Raises an AddrConversionError if IPv6 address cannot be converted to IPv4.

### ipv6(self, ipv4_compatible=False) |
Please Note: the IPv4-mapped IPv6 address format is now considered deprecated. See RFC 4291 or later for details. Parameters: `ipv4_compatible` - If `True` returns an IPv4-mapped address (::ffff:x.x.x.x), an IPv4-compatible (::x.x.x.x) address otherwise. Default: False (IPv4-mapped). Returns: A numerically equivalent version 6 IPAddress object.

### format(self, dialect=None) |
Only relevant for IPv6 addresses. Has no effect for IPv4. Parameters: `dialect` - An ipv6_* dialect class. Returns: an alternate string representation for this IP address.

### __or__(self, other) (Or operator) |
Parameters: `other` - An IPAddress object (or other int-like object). Returns: bitwise OR (x | y) between the integer value of this IP address and `other`.

### __and__(self, other) (And operator) |
Parameters: `other` - An IPAddress object (or other int-like object). Returns: bitwise AND (x & y) between the integer value of this IP address and `other`.

### __xor__(self, other) (Exclusive-Or operator) |
Parameters: `other` - An IPAddress object (or other int-like object). Returns: bitwise exclusive OR (x ^ y) between the integer value of this IP address and `other`.

### __lshift__(self, numbits) |
Parameters: `numbits` - size of bitwise shift. Returns: an IPAddress object based on this one with its integer value left shifted by `numbits`.

### __rshift__(self, numbits) |
Parameters: `numbits` - size of bitwise shift. Returns: an IPAddress object based on this one with its integer value right shifted by `numbits`.

### __nonzero__(self) (Boolean test operator) |
Returns: `True` if the numerical value of this IP address is not zero, `False` otherwise.

### __bool__(self) |
Returns: `True` if the numerical value of this IP address is not zero, `False` otherwise.

### __str__(self) (Informal representation operator) |
str(x) Returns: IP address in presentational format Overrides: object.__str__

### __repr__(self) (Representation operator) |
repr(x) Returns: Python statement to create an equivalent object Overrides: object.__repr__

Property Details | [hide private]

### packed The value of this IP address as a packed binary string. Get Method: unreachable.packed(self) - The value of this IP address as a packed binary string.

### words A list of unsigned integer words (octets for IPv4, hextets for IPv6) found in this IP address. Get Method: unreachable.words(self) - A list of unsigned integer words (octets for IPv4, hextets for IPv6) found in this IP address.

### bin The value of this IP adddress in standard Python binary representational form (0bxxx). A back port of the format provided by the builtin bin() function found in Python 2.6.x and higher. Get Method: unreachable.bin(self) - The value of this IP adddress in standard Python binary representational form (0bxxx).

### reverse_dns The reverse DNS lookup record for this IP address Get Method: unreachable.reverse_dns(self) - The reverse DNS lookup record for this IP address