Module ipaddr :: Class IPv4
[show private | hide private]
[frames | no frames]

Type IPv4

object --+    
         |    
    BaseIP --+
             |
            IPv4


This class represents and manipulates 32-bit IPv4 addresses.

Attributes: [examples for IPv4('1.2.3.4/27')]
    .ip: 16909060
    .ip_ext: '1.2.3.4'
    .ip_ext_full: '1.2.3.4'
    .network: 16909056L
    .network_ext: '1.2.3.0'
    .hostmask: 31L (0x1F)
    .hostmask_ext: '0.0.0.31'
    .broadcast: 16909087L (0x102031F)
    .broadcast_ext: '1.2.3.31'
    .netmask: 4294967040L (0xFFFFFFE0)
    .netmask_ext: '255.255.255.224'
    .prefixlen: 27

Method Summary
  __init__(self, ipaddr)
Instantiate a new IPv4 object.
  IsLinkLocal(self)
Test if the address is reserved for LinkLocal.
  IsLoopback(self)
Test if the address is a loopback adddress.
  IsMulticast(self)
Test if the address is reserved for multicast use.
  IsRFC1918(self)
Test if the IPv4 address is reserved per RFC1918.
  SetPrefix(self, prefixlen)
Change the prefix length.
  Subnet(self, prefixlen_diff)
The subnets which join to make the current subnet.
  Supernet(self, prefixlen_diff)
The supernet containing the current network.
    Inherited from BaseIP
  __cmp__(self, other)
  __contains__(self, other)
Return True if other is contained by self.
  __eq__(self, other)
  __getitem__(self, n)
  __hash__(self)
  __hex__(self)
  __int__(self)
  __ne__(self, other)
  __repr__(self)
  __str__(self)
  AddressExclude(self, other)
Remove an address from a larger block.
  CompareNetworks(self, other)
Compare two IP objects.
  Contains(self, other)
Return True if other is contained by self.
    Inherited from object
  __delattr__(...)
x.__delattr__('name') <==> del x.name
  __getattribute__(...)
x.__getattribute__('name') <==> x.name
  __new__(T, S, ...)
T.__new__(S, ...) -> a new object with type S, a subtype of T
  __reduce__(...)
helper for pickle
  __reduce_ex__(...)
helper for pickle
  __setattr__(...)
x.__setattr__('name', value) <==> x.name = value

Property Summary
  version
    Inherited from BaseIP
  broadcast
  broadcast_ext
  hostmask
  hostmask_ext
  ip_ext
  ip_ext_full
  netmask_ext
  network
  network_ext
  numhosts

Method Details

__init__(self, ipaddr)
(Constructor)

Instantiate a new IPv4 object.

Args:
    ipaddr: A string or integer representing the IP [& network].
      '192.168.1.1/32'
      '192.168.1.1/255.255.255.255'
      '192.168.1.1/0.0.0.255'
      '192.168.1.1'
      are all functionally the same in IPv4. That is to say,
      failing to provide a subnetmask will create an object with
      a mask of /32. A netmask of '255.255.255.255' is assumed
      to be /32 and '0.0.0.0' is assumed to be /0, even though
      other netmasks can be expressed both as host- and
      net-masks. (255.0.0.0 == 0.255.255.255)

      Additionally, an integer can be passed, so
      IPv4('192.168.1.1') == IPv4(3232235777).
      or, more generally
      IPv4(IPv4('192.168.1.1').ip) == IPv4('192.168.1.1')

Raises:
    IPv4IpValidationError: If ipaddr isn't a valid IPv4 address.
    IPv4NetmaskValidationError: If the netmask isn't valid for
      an IPv4 address.
Overrides:
__builtin__.object.__init__

IsLinkLocal(self)

Test if the address is reserved for LinkLocal.

Returns:
    A boolean, True if the address is link local.

IsLoopback(self)

Test if the address is a loopback adddress.

Returns:
    A boolean, True if the address is a loopback.

IsMulticast(self)

Test if the address is reserved for multicast use.

Returns:
    A boolean, True if the address is multicast.

IsRFC1918(self)

Test if the IPv4 address is reserved per RFC1918.

Returns:
    A boolean, True if the address is reserved.

SetPrefix(self, prefixlen)

Change the prefix length.

Args:
    prefixlen: An integer, the new prefix length.

Raises:
    IPv4NetmaskValidationError: If prefixlen is out of bounds.

Subnet(self, prefixlen_diff=1)

The subnets which join to make the current subnet.

In the case that self contains only one IP
(self.prefixlen == 32), return a list with just ourself.

Args:
    prefixlen_diff: An integer, the amount the prefix length
      should be increased by.  Given a /24 network and a
      prefixlen_diff of 3, for example, 8 subnets of size /27
      will be returned.  The default value of 1 splits the
      current network into two halves.

Returns:
    A list of IPv4 objects.

Raises:
    PrefixlenDiffInvalidError: The prefixlen_diff is too small
      or too large.

Supernet(self, prefixlen_diff=1)

The supernet containing the current network.

Args:
    prefixlen_diff: An integer, the amount the prefix length of
      the network should be decreased by.  For example, given a
      /24 network and a prefixlen_diff of 3, a supernet with a
      /21 netmask is returned.

Returns:
    An IPv4 object.

Raises:
    PrefixlenDiffInvalidError: If
      self.prefixlen - prefixlen_diff < 0. I.e., you have a
      negative prefix length.

Property Details

version

Get Method:
version(...)

Generated by Epydoc 2.1 on Tue Feb 3 11:02:37 2009 http://epydoc.sf.net