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
You may use iprange_to_cidrs provided by netaddr module. Example:
iprange_to_cidrs
pip install netaddr
import netaddr cidrs = netaddr.iprange_to_cidrs(startip, endip)
Here are the official docs: https://netaddr.readthedocs.io/