Package netaddr :: Module address :: Class IP
[frames] | no frames]

Class IP

source code

object --+    
         |    
      Addr --+
             |
            IP

A class whose objects represent Internet Protocol network addresses. Both IPv4 and IPv6 are fully supported and include an optional subnet bit mask prefix, for example :

   192.168.0.1/24
   fe80::20f:1fff:fe12:e733/64

This class does not make a requirement to omit non-zero bits to the right of the subnet prefix when it is applied to the address.

See the CIDR() class if you require *strict* subnet prefix checking.

Instance Methods
 
__init__(self, addr, addr_type=0)
Constructor.
source code
 
setvalue(self, addr)
Sets the value of this address.
source code
 
is_netmask(self)
Returns: True if this addr is a mask that would return a host id, False otherwise.
source code
 
prefixlen(self)
Returns: The number of bits set to one in this address if it is a netmask, zero otherwise.
source code
 
reverse_dns(self)
Returns: The reverse DNS lookup string for this IP address.
source code
 
is_hostmask(self)
Returns: True if this address is a mask that would return a host id, False otherwise.
source code
 
cidr(self)
Returns: A valid CIDR object for this IP address.
source code
 
masklen(self)
Returns: The subnet prefix of this IP address.
source code
 
__str__(self)
Returns: The common string representation for this IP address.
source code
 
__repr__(self)
Returns: An executable Python statement that can recreate an object with an equivalent state.
source code

Inherited from Addr: __eq__, __ge__, __getitem__, __gt__, __hex__, __iadd__, __int__, __isub__, __iter__, __le__, __len__, __long__, __lt__, __setitem__, bits, family

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __setattr__

Properties

Inherited from object: __class__

Method Details

__init__(self, addr, addr_type=0)
(Constructor)

source code 

Constructor.

Parameters:
  • addr - an IPv4 or IPv6 address string with an optional subnet prefix or a network byte order integer.
  • addr_type - (optional) the IP address type (AT_INET or AT_INET6). If addr is an integer, this argument is mandatory.
Overrides: object.__init__

setvalue(self, addr)

source code 

Sets the value of this address.

Parameters:
  • addr - the string form of an IP address, or a network byte order int/long value within the supported range for the address type.
    • Raises a TypeError if addr is of an unsupported type.
    • Raises an OverflowError if addr is an integer outside the bounds for this address type.
Overrides: Addr.setvalue

is_netmask(self)

source code 
Returns:
True if this addr is a mask that would return a host id, False otherwise.

prefixlen(self)

source code 
Returns:
The number of bits set to one in this address if it is a netmask, zero otherwise.

reverse_dns(self)

source code 
Returns:
The reverse DNS lookup string for this IP address.

is_hostmask(self)

source code 
Returns:
True if this address is a mask that would return a host id, False otherwise.

cidr(self)

source code 
Returns:
A valid CIDR object for this IP address.

masklen(self)

source code 
Returns:
The subnet prefix of this IP address.

__str__(self)
(Informal representation operator)

source code 

str(x)

Returns:
The common string representation for this IP address.
Overrides: object.__str__

__repr__(self)
(Representation operator)

source code 

repr(x)

Returns:
An executable Python statement that can recreate an object with an equivalent state.
Overrides: object.__repr__