IPy is a Python module for handling IPv4 and IPv6 Addresses and Networks in
a fashion similar to perl's Net::IP and friends. The IP class allows a
comfortable parsing and handling for most notations in use for IPv4 and IPv6
Addresses and Networks.
It enables code like this:
>>> ip = IP('127.0.0.0/30')
>>> for x in ip:
... print x
...
127.0.0.0
127.0.0.1
127.0.0.2
127.0.0.3
>>> ip2 = IP('0x7f000000/30')
>>> ip == ip2
1
>>> ip.reverseNames()
['0.0.0.127.in-addr.arpa.', '1.0.0.127.in-addr.arpa.',
'2.0.0.127.in-addr.arpa.', '3.0.0.127.in-addr.arpa.']
>>> ip.reverseName()
'0-3.0.0.127.in-addr.arpa.'
>>> ip.iptype()
'RESERVED'
It can detect about a dozen different ways of expressing IP addresses and
networks, parse them and distinguish between IPv4 and IPv6 addresses.
>>> IP('10.0.0.0/8').version()
4
>>> IP('::1').version()
6
>>> print IP(0x7f000001)
127.0.0.1
>>> print IP('0x7f000001')
127.0.0.1
>>> print IP('127.0.0.1')
127.0.0.1
>>> print IP('10')
10.0.0.0
>>> print IP('1080:0:0:0:8:800:200C:417A')
1080:0000:0000:0000:0008:0800:200c:417a
>>> print IP('1080::8:800:200C:417A')
1080:0000:0000:0000:0008:0800:200c:417a
>>> print IP('::1')
0000:0000:0000:0000:0000:0000:0000:0001
>>> print IP('::13.1.68.3')
0000:0000:0000:0000:0000:0000:0d01:4403
>>> 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
>>> IP('10.0.0.0/24').strNormal(q)
'10.0.0.0/24'
>>> IP('10.0.0.0/24').strNormal(2)
'10.0.0.0/255.255.255.0'
>>> IP('10.0.0.0/24').strNormal(3)
'10.0.0.0-10.0.0.255'
To install type
$ python setup.py install
$ pydoc -w IPy
$ cd test
$ python test_IPy.py
Read IPy.html for usage Instructions.
IPy has been tested with python 2.2 and pyton 2.1.
Further Information can be found at http://c0re.jp/c0de/IPy/
--drt@un.bewaff.net