Home | Trees | Indices | Help |
---|
|
Handling of IP addresses returning integers.
Use class IP instead because some features are not implemented for IPint.
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|
Create an instance of an IP object. Data can be a network specification or a single IP. IP Addresses can be specified in all forms understood by parseAddress.() the size of a network can be specified as /prefixlen a.b.c.0/24 2001:658:22a:cafe::/64 -lastIP a.b.c.0-a.b.c.255 2001:658:22a:cafe::-2001:658:22a:cafe:ffff:ffff:ffff:ffff /decimal netmask a.b.c.d/255.255.255.0 not supported for IPv6 If no size specification is given a size of 1 address (/32 for IPv4 and /128 for IPv6) is assumed. >>> print IP('127.0.0.0/8') 127.0.0.0/8 >>> print IP('127.0.0.0/255.0.0.0') 127.0.0.0/8 >>> print IP('127.0.0.0-127.255.255.255') 127.0.0.0/8 See module documentation for more examples. |
Return the first / base / network addess as an (long) integer. The same as IP[0]. >>> "%X" % IP('10.0.0.0/8').int() 'A000000' |
Return the IP version of this Object. >>> IP('10.0.0.0/8').version() 4 >>> IP('::1').version() 6 |
Returns Network Prefixlen. >>> IP('10.0.0.0/8').prefixlen() 8 |
Return the broadcast (last) address of a network as an (long) integer. The same as IP[-1]. |
Prints Prefixlen/Netmask. Not really. In fact it is our universal Netmask/Prefixlen printer. This is considered an internel function. want == 0 / None don't return anything 1.2.3.0 want == 1 /prefix 1.2.3.0/24 want == 2 /netmask 1.2.3.0/255.255.255.0 want == 3 -lastip 1.2.3.0-1.2.3.255 |
Return a string representation as a binary value. >>> print IP('127.0.0.1').strBin() 01111111000000000000000000000001 |
Return a string representation in compressed format using '::' Notation. >>> IP('127.0.0.1').strCompressed() '127.0.0.1' >>> IP('2001:0658:022a:cafe:0200::1').strCompressed() '2001:658:22a:cafe:200::1' >>> IP('ffff:ffff:ffff:ffff:ffff:f:f:fffc/127').strCompressed() 'ffff:ffff:ffff:ffff:ffff:f:f:fffc/127' |
Return a string representation in the usual format. >>> print IP('127.0.0.1').strNormal() 127.0.0.1 >>> print IP('2001:0658:022a:cafe:0200::1').strNormal() 2001:658:22a:cafe:200:0:0:1 |
Return a string representation in the non mangled format. >>> print IP('127.0.0.1').strFullsize() 127.0.0.1 >>> print IP('2001:0658:022a:cafe:0200::1').strFullsize() 2001:0658:022a:cafe:0200:0000:0000:0001 |
Return a string representation in hex format in lower case. >>> IP('127.0.0.1').strHex() '0x7f000001' >>> IP('2001:0658:022a:cafe:0200::1').strHex() '0x20010658022acafe0200000000000001' |
Return a string representation in decimal format. >>> print IP('127.0.0.1').strDec() 2130706433 >>> print IP('2001:0658:022a:cafe:0200::1').strDec() 42540616829182469433547762482097946625 |
Return a description of the IP type ('PRIVATE', 'RESERVERD', etc). >>> print IP('127.0.0.1').iptype() PRIVATE >>> print IP('192.168.1.1').iptype() PRIVATE >>> print IP('195.185.1.2').iptype() PUBLIC >>> print IP('::1').iptype() LOOPBACK >>> print IP('2001:0658:022a:cafe:0200::1').iptype() ASSIGNABLE RIPE The type information for IPv6 is out of sync with reality. |
Return netmask as an integer. >>> "%X" % IP('195.185.0.0/16').netmask().int() 'FFFF0000' |
Return netmask as an string. Mostly useful for IPv6. >>> print IP('195.185.0.0/16').strNetmask() 255.255.0.0 >>> print IP('2001:0658:022a:cafe::0/64').strNetmask() /64 |
Return the length of an subnet. >>> print IP('195.185.1.0/28').len() 16 >>> print IP('195.185.1.0/24').len() 256 |
All IPy objects should evaluate to true in boolean context. Ordinarily, they do, but if handling a default route expressed as 0.0.0.0/0, the __len__() of the object becomes 0, which is used as the boolean value of the object. |
Return the length of an subnet. Called to implement the built-in function len(). It breaks with IPv6 Networks. Anybody knows how to fix this. |
Called to implement evaluation of self[key]. >>> ip=IP('127.0.0.0/30') >>> for x in ip: ... print repr(x) ... IP('127.0.0.0') IP('127.0.0.1') IP('127.0.0.2') IP('127.0.0.3') >>> ip[2] IP('127.0.0.2') >>> ip[-1] IP('127.0.0.3') |
Called to implement membership test operators. Should return true if item is in self, false otherwise. Item can be other IP-objects, strings or ints. >>> IP('195.185.1.1').strHex() '0xc3b90101' >>> 0xC3B90101L in IP('195.185.1.0/24') 1 >>> '127.0.0.1' in IP('127.0.0.0/24') 1 >>> IP('127.0.0.0/24') in IP('127.0.0.0/25') 0 |
Check if two IP address ranges overlap. Returns 0 if the two ranged don't overlap, 1 if the given range overlaps at the end and -1 if it does at the beginning. >>> IP('192.168.0.0/23').overlaps('192.168.1.0/24') 1 >>> IP('192.168.0.0/23').overlaps('192.168.1.255') 1 >>> IP('192.168.0.0/23').overlaps('192.168.2.0') 0 >>> IP('192.168.1.0/24').overlaps('192.168.0.0/23') -1 |
Dispatch to the prefered String Representation. Used to implement str(IP). |
Print a representation of the Object. Used to implement repr(IP). Returns a string which evaluates to an identical Object (without the wnatprefixlen stuff - see module docstring. >>> print repr(IP('10.0.0.0/24')) IP('10.0.0.0/24') |
Called by comparison operations. Should return a negative integer if self < other, zero if self == other, a positive integer if self > other. Networks with different prefixlen are considered non-equal. Networks with the same prefixlen and differing addresses are considered non equal but are compared by thair base address integer value to aid sorting of IP objects. The Version of Objects is not put into consideration. >>> IP('10.0.0.0/24') > IP('10.0.0.0') 1 >>> IP('10.0.0.0/24') < IP('10.0.0.0') 0 >>> IP('10.0.0.0/24') < IP('12.0.0.0/24') 1 >>> IP('10.0.0.0/24') > IP('12.0.0.0/24') 0 |
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. The only required property is that objects which compare equal have the same hash value >>> IP('10.0.0.0/24').__hash__() -167772185 |
Home | Trees | Indices | Help |
---|
Generated by Epydoc 3.0.1 on Wed Jun 9 23:05:09 2010 | http://epydoc.sourceforge.net |