1、IPy的安装
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
[root@plinuxos ~]
# wget https://pypi.python.org/packages/source/I/IPy/IPy-0.81.tar.gz --no-check-certificate
[root@plinuxos ~]
# tar zxvf IPy-0.81.tar.gz
IPy-0.81/
IPy-0.81
/test/
IPy-0.81
/test/test
.rst
IPy-0.81
/test/test_IPy
.py
IPy-0.81
/setup
.py
IPy-0.81
/ChangeLog
IPy-0.81
/README
IPy-0.81
/IPy
.py
IPy-0.81
/example/
IPy-0.81
/example/confbuilder
.py
IPy-0.81
/example/confbuilder
IPy-0.81
/PKG-INFO
IPy-0.81
/MANIFEST
.
in
IPy-0.81
/COPYING
IPy-0.81
/test_doc
.py
IPy-0.81
/AUTHORS
[root@plinuxos ~]
# cd IPy-0.81
[root@plinuxos IPy-0.81]
# python setup.py install
running
install
running build
running build_py
creating build
creating build
/lib
copying IPy.py -> build
/lib
running install_lib
copying build
/lib/IPy
.py ->
/usr/lib/python2
.7
/site-packages
running install_egg_info
Writing
/usr/lib/python2
.7
/site-packages/IPy-0
.81-py2.7.egg-info
|
2、IPy的使用
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
>>>
from
IPy
import
IP
>>> ip
=
IP(
'122.112.253.192/26'
)
>>>
print
ip.
len
()
##输出网段IP数
64
>>>
for
x
in
ip:
...
print
(x)
##列出网段所有IP
...
122.112
.
253.192
122.112
.
253.193
122.112
.
253.194
......
122.112
.
253.250
122.112
.
253.251
122.112
.
253.252
122.112
.
253.253
122.112
.
253.254
122.112
.
253.255
>>>
>>>
print
(ip.net())
##网段
122.112
.
253.192
>>>
print
(ip.netmask())
##掩码
255.255
.
255.192
>>>
print
(ip.reverseNames()[
0
])
##反向地址
192.253
.
112.122
.
in
-
addr.arpa.
>>>
print
(ip.reverseNames()[
1
])
193.253
.
112.122
.
in
-
addr.arpa.
>>>
print
(ip.strHex())
##十六进制
0x7a70fdc0
>>>
print
(ip.strBin())
##二进制
01111010011100001111110111000000
>>>
print
(ip.iptype())
##ip地址类型
PUBLIC
本文转自Grodd51CTO博客,原文链接:http://blog.51cto.com/juispan/1964523,如需转载请自行联系原作者
|