如何在较大的一个中缩小连续的B ip类 [英] how to shrink consecutive B ip classes in bigger one

查看:198
本文介绍了如何在较大的一个中缩小连续的B ip类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

阅读 Facebook使用的IP空间列表后:

Real列表是最后一个答案,但我想知道Igy(标记为解决方案的答案)是如何设法通过将连续类添加到更大的列中来大量缩小列表(通过相应地从每个新连续的网络掩码减少网络),是否有工具,或只有手动?

"Real" list is the last answer, but I wonder how Igy (with the answer marked as solution) managed to shrink the list a lot by adding consecutive classes into a bigger one (by decreasing accordingly from network mask for each new consecutive network), is there a tool, or only manually ?

这是防火墙的巨大改进,其中规则数量越多(越短越好)。

This is a HUGE improvement for firewall, where number of rules counts (the shorter the better).

推荐答案

一个简单的解决方案是使用 netaddr

A simple solution is to use netaddr:

import netaddr
ips = netaddr.IPSet()
for addr in all_addrs:
    ips.add(addr)
ips.compact()
for cidr in ips.iter_cidrs():
    print str(cidr)

这篇关于如何在较大的一个中缩小连续的B ip类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆