Reputation: 493
How can I convert many IP ranges into a CIDR notation? All I found is the ip2cidr service, but I have >200K IP-records.
Upvotes: 3
Views: 3971
Reputation: 3944
Using netaddr:
from netaddr import *
ips = ['192.168.37.111', '192.168.37.112']
all_ips = list(iter_iprange(ips[0], ips[1]))
ip_address = cidr_merge(all_ips)
cidr = []
for ip in ip_address:
cidr.append(str(ip.cidr))
Upvotes: 0
Reputation:
http://pypi.python.org/pypi?%3Aaction=search&term=cidr&submit=search
Upvotes: 3