[Tutor] dynamical program to create subnets CIDR

Mats Wichmann mats at wichmann.us
Wed Oct 16 12:03:19 EDT 2019


On 10/7/19 12:31 PM, ose micah via Tutor wrote:
> Hello All,
> Can anyone help with a program that could compare a list of IPs and create the least possible CIDR block sets from these IPs.
> for example.
> I have a list say:
> 202.238.149.0/22202.238.164.0/22202.238.168.0/23202.238.176.0/20202.238.174.0/23202.238.172.0/2320.226.12.224/2720.223.14.0/2410.32.0.0/1510.35.0.0/1610.54.63.128/2610.59.250.0/2610.224.0.0/2410.228.69.0/24
> I want to reduce this list to:
> 10.32.0.0/14202.238.149.0/19
> 10.224.0.0/1310.54.63.0/13
> 
> Thanks
> Ose Micah

don't know if this ever got resolved satisfactorily, but I ought to have 
piped in with the observation that there are existing tools for dealing 
with IP addresses in Python, which was part of the problem expressed 
here (I realize there was also a file-reading-and-processing part). A 
couple here:

https://pypi.org/project/iptools/
https://pypi.org/project/netaddr/

and some further hunting will probably turn up more.

Also don't forget the standard library's ipaddress module.


More information about the Tutor mailing list