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

Class IP

source code


Class for handling IP Addresses and Networks.

Instance Methods [hide private]
 
__add__(self, other)
Emulate numeric objects through network aggregation
source code
 
__getitem__(self, key)
Called to implement evaluation of self[key].
source code
 
__repr__(self)
Print a representation of the Object.
source code
 
broadcast(self)
Return the broadcast (last) address of a network as an IP object.
source code
 
net(self)
Return the base (first) address of a network as an IP object.
source code
 
netmask(self)
Return netmask as an IP object.
source code
 
reverseName(self)
Return the value for reverse lookup/PTR records as RfC 2317 look alike.
source code
 
reverseNames(self)
Return a list with values forming the reverse lookup.
source code
    Inherited from IPint
 
__cmp__(self, other)
Called by comparison operations.
source code
 
__contains__(self, item)
Called to implement membership test operators.
source code
 
__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.
source code
 
__init__(self, data, ipversion=0)
Create an instance of an IP object.
source code
 
__len__(self)
Return the length of an subnet.
source code
 
__nonzero__(self)
All IPy objects should evaluate to true in boolean context.
source code
 
__str__(self)
Dispatch to the prefered String Representation.
source code
 
_printPrefix(self, want)
Prints Prefixlen/Netmask.
source code
 
int(self)
Return the first / base / network addess as an (long) integer.
source code
 
iptype(self)
Return a description of the IP type ('PRIVATE', 'RESERVERD', etc).
source code
 
len(self)
Return the length of an subnet.
source code
 
overlaps(self, item)
Check if two IP address ranges overlap.
source code
 
prefixlen(self)
Returns Network Prefixlen.
source code
 
strBin(self, wantprefixlen=None)
Return a string representation as a binary value.
source code
 
strCompressed(self, wantprefixlen=None)
Return a string representation in compressed format using '::' Notation.
source code
 
strDec(self, wantprefixlen=None)
Return a string representation in decimal format.
source code
 
strFullsize(self, wantprefixlen=None)
Return a string representation in the non mangled format.
source code
 
strHex(self, wantprefixlen=None)
Return a string representation in hex format in lower case.
source code
 
strNetmask(self)
Return netmask as an string.
source code
 
strNormal(self, wantprefixlen=None)
Return a string representation in the usual format.
source code
 
version(self)
Return the IP version of this Object.
source code
Method Details [hide private]

__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__

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

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

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

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.

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