Package PyFoam :: Package ThirdParty :: Module IPy :: Class IP
[show private | hide private]
[frames | no frames]

Class IP

IPint --+
        |
       IP


Class for handling IP Addresses and Networks.
Method Summary
  __add__(self, other)
Emulate numeric objects through network aggregation
  __getitem__(self, key)
Called to implement evaluation of self[key].
  __repr__(self)
Print a representation of the Object.
  broadcast(self)
Return the broadcast (last) address of a network as an IP object.
  net(self)
Return the base (first) address of a network as an IP object.
  netmask(self)
Return netmask as an IP object.
  reverseName(self)
Return the value for reverse lookup/PTR records as RfC 2317 look alike.
  reverseNames(self)
Return a list with values forming the reverse lookup.
    Inherited from IPint
  __init__(self, data, ipversion)
Create an instance of an IP object.
  __cmp__(self, other)
Called by comparison operations.
  __contains__(self, item)
Called to implement membership test operators.
  __hash__(self)
Called for the key object for dictionary operations, and by the built-in function hash() Should return a 32-bit integer usable as a hash value for dictionary operations.
  __len__(self)
Return the length of an subnet.
  __nonzero__(self)
All IPy objects should evaluate to true in boolean context.
  __str__(self)
Dispatch to the prefered String Representation.
  int(self)
Return the first / base / network addess as an (long) integer.
  iptype(self)
Return a description of the IP type ('PRIVATE', 'RESERVERD', etc).
  len(self)
Return the length of an subnet.
  overlaps(self, item)
Check if two IP address ranges overlap.
  prefixlen(self)
Returns Network Prefixlen.
  strBin(self, wantprefixlen)
Return a string representation as a binary value.
  strCompressed(self, wantprefixlen)
Return a string representation in compressed format using '::' Notation.
  strDec(self, wantprefixlen)
Return a string representation in decimal format.
  strFullsize(self, wantprefixlen)
Return a string representation in the non mangled format.
  strHex(self, wantprefixlen)
Return a string representation in hex format in lower case.
  strNetmask(self)
Return netmask as an string.
  strNormal(self, wantprefixlen)
Return a string representation in the usual format.
  version(self)
Return the IP version of this Object.

Method Details

__add__(self, other)
(Addition operator)

Emulate numeric objects through network aggregation

__getitem__(self, key)
(Indexing operator)

Called to implement evaluation of self[key].
>>> ip=IP('127.0.0.0/30')
>>> for x in ip:
...  print str(x)
...

127.0.0.0
127.0.0.1
127.0.0.2
127.0.0.3

>>> print str(ip[2])
127.0.0.2

>>> print str(ip[-1])
127.0.0.3
Overrides:
PyFoam.ThirdParty.IPy.IPint.__getitem__

__repr__(self)
(Representation operator)

Print a representation of the Object.
>>> IP('10.0.0.0/8')
IP('10.0.0.0/8')
Overrides:
PyFoam.ThirdParty.IPy.IPint.__repr__

broadcast(self)

Return the broadcast (last) address of a network as an IP object.

The same as IP[-1].
>>> IP('10.0.0.0/8').broadcast()
IP('10.255.255.255')
Overrides:
PyFoam.ThirdParty.IPy.IPint.broadcast

net(self)

Return the base (first) address of a network as an IP object.

The same as IP[0].
>>> IP('10.0.0.0/8').net()
IP('10.0.0.0')
Overrides:
PyFoam.ThirdParty.IPy.IPint.net

netmask(self)

Return netmask as an IP object.
>>> IP('10.0.0.0/8').netmask()
IP('255.0.0.0')
Overrides:
PyFoam.ThirdParty.IPy.IPint.netmask

reverseName(self)

Return the value for reverse lookup/PTR records as RfC 2317 look alike.

RfC 2317 is an ugly hack which only works for sub-/24 e.g. not for /23. Do not use it. Better set up a Zone for every address. See reverseName for a way to arcive that.
>>> print IP('195.185.1.1').reverseName()
1.1.185.195.in-addr.arpa.

>>> print IP('195.185.1.0/28').reverseName()
0-15.1.185.195.in-addr.arpa.

reverseNames(self)

Return a list with values forming the reverse lookup.
>>> IP('213.221.113.87/32').reverseNames()
['87.113.221.213.in-addr.arpa.']

>>> IP('213.221.112.224/30').reverseNames()
['224.112.221.213.in-addr.arpa.', '225.112.221.213.in-addr.arpa.', '226.112.221.213.in-addr.arpa.', '227.112.221.213.in-addr.arpa.']

>>> IP('127.0.0.0/24').reverseNames()
['0.0.127.in-addr.arpa.']

>>> IP('127.0.0.0/23').reverseNames()
['0.0.127.in-addr.arpa.', '1.0.127.in-addr.arpa.']

>>> IP('127.0.0.0/16').reverseNames()
['0.127.in-addr.arpa.']

>>> IP('127.0.0.0/15').reverseNames()
['0.127.in-addr.arpa.', '1.127.in-addr.arpa.']

>>> IP('128.0.0.0/8').reverseNames()
['128.in-addr.arpa.']

>>> IP('128.0.0.0/7').reverseNames()
['128.in-addr.arpa.', '129.in-addr.arpa.']

Generated by Epydoc 2.1 on Mon Jan 22 23:52:48 2007 http://epydoc.sf.net