用python编写的快速ipv4和ipv6前缀聚合器。
aggregate-prefixes的Python项目详细描述
聚合前缀
用python编写的快速ipv4和ipv6前缀聚合器。
从参数或sdtin获取未排序的IPv4或IPv6前缀的列表,并将已排序的聚合列表返回给stdout 错误转到stderr。
可执行文件的cli语法
usage: aggregate-prefixes [-h] [--max-length [LENGTH]] [--truncate [MASK]] [--verbose] [--version] prefixes Aggregates IPv4 or IPv6 prefixes from file or STDIN positional arguments: prefixes Text file of unsorted list of IPv4 or IPv6 prefixes. Use '-' for STDIN. optional arguments: -h, --help show this help message and exit --max-length [LENGTH], -m [LENGTH] Discard longer prefixes prior to processing --truncate [MASK], -t [MASK] Ttruncate IP/mask to network/mask --verbose, -v Display verbose information about the optimisations --version, -V show program's version number and exit
作为模块使用
$ python
Python 2.7.14+ (default, Apr 2 2018, 04:16:25)
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> from aggregate_prefixes import aggregate_prefixes
>>> list(aggregate_prefixes(['192.0.2.0/32', '192.0.2.1/32', '192.0.2.2/32']))
['192.0.2.0/31', '192.0.2.2/32']
>>>
python兼容性
测试时间:
- Python2.7.15
- Python3.6.5