码迷,mamicode.com
首页 > 其他好文 > 详细

如何合并IP网段

时间:2015-08-06 01:49:08      阅读:820      评论:0      收藏:0      [点我收藏+]

标签:

1. 安装IPy

pip3 install IPy

2. 写脚本:

yuyue@workplace:~ $ cat combine_ip.py
from IPy import IPSet, IP
import sys

def handler(file_name):
ret = IPSet()
for ip in open(file_name):
ip = "%s/24"%(ip)
ret.add(IP(ip, make_net = True))

for item in ret:
print(item)

if __name__ == "__main__":

file_name = sys.argv[1]
handler(file_name)

 

3. 开始执行,明明已经安装成功了,怎么执行脚本报错呢?

yuyue@workplace:~ $ python combine_ip.py
Traceback (most recent call last):
File "combine_ip.py", line 1, in <module>
from IPy import IPSet, IP
ImportError: No module named IPy

4. 找一找IPy装到哪里去了?

yuyue@workplace:~ $ sudo find / -name "*IPy*"
Password:
find: /dev/fd/3: Not a directory
find: /dev/fd/4: Not a directory
/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/__pycache__/IPy.cpython-34.pyc
/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/IPy-0.83-py3.4.egg-info
/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/IPy.py

 

4. 执行 python3.4 combine_ip.py ip.list   ok !! 

 

==============分割线==============

http://www.ab126.com/goju/1840.html

 

>>> from ipcalc import Network

>>> net = Network(‘10.153.192.0/21‘)

>>> net.netmask()

IP(‘255.255.248.0‘)

>>> net.host_first()

IP(‘10.153.192.1‘)

>>> net.host_last()

IP(‘10.153.199.254‘)

>>> net.broadcast()

IP(‘10.153.199.255‘)

如何合并IP网段

标签:

原文地址:http://www.cnblogs.com/yuyue2014/p/4706213.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!