List of IP addresses in Python to a list of CIDR

后端 未结 6 1150
温柔的废话
温柔的废话 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:05

    You can do it in one line using netaddr:

    cidrs = netaddr.iprange_to_cidrs(ip_start, ip_end)
    

提交回复
热议问题