4 ms·
And you don't even have to invent the aggregation from scratch https://cidr-aggregator.pages.dev/ https://cidr-aggregator.pages.dev/
by hughesjj 2y ago
And you don't even have to invent the aggregation from scratch
https://cidr-aggregator.pages.dev/ https://cidr-aggregator.pages.dev/
- LinuxBender 2y agoI don't remember where I found this but there is also some perl code that will do it. I wish they added a comment so I could give them credit. I use it to build block lists for adding null routes on hobby web servers using a few blocklists from around the web and for importing data from BGP AS databases. It keeps my routing table below 300K. It's only for ipv4. [Edit] I think this might be where I found it [1] #!/usr/bin/perl use strict; use warnings; use Net::CIDR::Lite; my $ipv4String='[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}'; if(defined $ARGV[0] && $ARGV[0] eq '-h'){ print "usage: $0 This script summarizes your IP classes (if possible). Input IPs with mask one per line. End with CTRL+D. Optionally, redirect a file to stdin like so: $0 < cidr.txt "; exit; } print "Enter IP/Mask one per line (1.2.3.0/24). End with CTRL+D.\n"; my $cidr =Net::CIDR::Lite->new; while(<>){ if(/($ipv4String\/[0-9]{1,2})/){ my $item=$1; $cidr->add($item); } else{ print "Ignoring previous line.\n"; } } my @cidr_list = $cidr->list; print "======Aggregated IP list:======\n"; foreach my $item(@cidr_list){ print "$item\n"; } [1] - https://adrianpopagh.blogspot.com/2008/03/route-summarization-script.html https://adrianpopagh.blogspot.com/2008/03/route-summarizatio...
- quectophoton 2y agoIf using Python, there's a nice method too: https://docs.python.org/3/library/ipaddress.html#ipaddress.collapse_addresses https://docs.python.org/3/library/ipaddress.html#ipaddress.c...