安装与使用IPy模块

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  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,如需转载请自行联系原作者

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值