如何合并IP网段

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')

转载于:https://www.cnblogs.com/yuyue2014/p/4706213.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值