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

Class IP

source code

IPint --+
        |
       IP

Class for handling IP Addresses and Networks.

Instance Methods [hide private]
 
net(self)
Return the base (first) address of a network as an IP object.
source code
 
broadcast(self)
Return the broadcast (last) address of a network as an IP object.
source code
 
netmask(self)
Return netmask as an IP object.
source code
 
reverseNames(self)
Return a list with values forming the reverse lookup.
source code
 
reverseName(self)
Return the value for reverse lookup/PTR records as RfC 2317 look alike.
source code
 
__getitem__(self, key)
Called to implement evaluation of self[key].
source code
 
__repr__(self)
Print a representation of the Object.
source code
 
__add__(self, other)
Emulate numeric objects through network aggregation
source code

Inherited from IPint: __cmp__, __contains__, __hash__, __init__, __len__, __nonzero__, __str__, int, iptype, len, overlaps, prefixlen, strBin, strCompressed, strDec, strFullsize, strHex, strNetmask, strNormal, version

Inherited from IPint (private): _printPrefix

Method Details [hide private]

net(self)

source code 

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: IPint.net

broadcast(self)

source code 

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: IPint.broadcast

netmask(self)

source code 

Return netmask as an IP object.

>>> IP('10.0.0.0/8').netmask()
IP('255.0.0.0')
Overrides: IPint.netmask

reverseNames(self)

source code 

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.']

reverseName(self)

source code 

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.

__getitem__(self, key)
(Indexing operator)

source code 

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: IPint.__getitem__

__repr__(self)
(Representation operator)

source code 

Print a representation of the Object.

>>> IP('10.0.0.0/8')
IP('10.0.0.0/8')
Overrides: IPint.__repr__