作为一名SA,常与IP、网络打交道,自然少不了关于IP地址的处理,现给大家推荐一个非常棒的python IP处理模块,它类似于。能够处理IPV4及IPV6的地址。
下载地址
安装
引用
tar -zxvf IPy-0.42.tar.gz
cd IPy-0.42
python setup.py install
简单例子
- >>> import IPy
- >>> IPy.IP('10.0.0.0/8').version()
- 4
- >>> IPy.IP('::1').version()
- 6
- >>> print IPy.IP(0x7f000001)
- 127.0.0.1
- >>> print IPy.IP('0x7f000001')
- 127.0.0.1
- >>> print IPy.IP('127.0.0.1')
- 127.0.0.1
- >>> print IPy.IP('10')
- 10.0.0.0
-
- >>> print IPy.IP('1080:0:0:0:8:800:200C:417A')
- 1080:0000:0000:0000:0008:0800:200c:417a
- >>> print IPy.IP('1080::8:800:200C:417A')
- 1080:0000:0000:0000:0008:0800:200c:417a
- >>> print IPy.IP('::1')
- 0000:0000:0000:0000:0000:0000:0000:0001
- >>> print IPy.IP('::13.1.68.3')
- 0000:0000:0000:0000:0000:0000:0d01:4403
-
- >>> print IPy.IP('127.0.0.0/8')
- 127.0.0.0/8
- >>> print IPy.IP('127.0.0.0/255.0.0.0')
- 127.0.0.0/8
- >>> print IPy.IP('127.0.0.0-127.255.255.255')
- 127.0.0.0/8
-
- >>> IPy.IP('10.0.0.0/24').strNormal(q)
- '10.0.0.0/24'
- >>> IPy.IP('10.0.0.0/24').strNormal(2)
- '10.0.0.0/255.255.255.0'
- >>> IPy.IP('10.0.0.0/24').strNormal(3)
- '10.0.0.0-10.0.0.255'
阅读(1282) | 评论(0) | 转发(0) |