List of IP addresses in Python to a list of CIDR

后端 未结 6 1213
温柔的废话
温柔的废话 2021-01-03 04:21

How do I convert a list of IP addresses to a list of CIDRs? Google\'s ipaddr-py library has a method called summarize_address_range(first, last) that converts two IP addres

6条回答
  •  太阳男子
    2021-01-03 05:13

    For the comment made by CaTalyst.X, note that you need to change to code in order for it to work.

    This:

    cidrs = netaddr.ip_range_to_cidrs('54.64.0.0', '54.71.255.255')
    

    Needs to become this:

    cidrs = netaddr.iprange_to_cidrs('54.64.0.0', '54.71.255.255')
    

    If you use the first instance of the code, you'll get an exception since ip_range_to_cidrs isn't a valid attribute to the netaddr method.

提交回复
热议问题