IP Range to CIDR conversion in Python?

前端 未结 2 1929
暖寄归人
暖寄归人 2020-12-29 07:05

How can I get a CIDR notation representing a range of IP addresses, given the start and end IP addresses of the range, in Python? I can find CIDR to IP Range but cannot find

2条回答
  •  抹茶落季
    2020-12-29 07:46

    You may use iprange_to_cidrs provided by netaddr module. Example:

    pip install netaddr
    
    import netaddr
    cidrs = netaddr.iprange_to_cidrs(startip, endip)
    

    Here are the official docs: https://netaddr.readthedocs.io/

提交回复
热议问题