<div dir="ltr"><span style="font-family:monospace">#!/usr/bin/perl<br>use strict;<br>use warnings;<br>use Data::Dumper;<br>use NetAddr::IP qw(Compact);<br><br>my @ips = ( '<a href="http://105.170.72.0/24">105.170.72.0/24</a>', '<a href="http://105.170.73.0/24">105.170.73.0/24</a>', '<a href="http://105.170.74.0/24">105.170.74.0/24</a>' );<br><br>my @agged = aggregate(\@ips);<br><br>sub aggregate {<br>        my @naddr = map { NetAddr::IP->new($_) } @{$_[0]};<br>        my @output = Compact(@naddr);<br>        return @output;<br>}</span><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Oct 1, 2020 at 8:36 AM John Von Essen <<a href="mailto:john@essenz.com">john@essenz.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Sorry if this is slightly off-topic, but I am writing some code for a custom GeoDNS routemap. My starting data set is a raw list of /24 subnets, no prefix aggregation has been done. In other words, its the entire BGP routing table in /24 prefixes - tagged by Geo region. Each region is its own txt file with a dump of /24’s. As a result, these lists are HUGE. I want to aggregate the prefixes as much as possible to create a smaller routemap.<br>
<br>
So right now it looks like:<br>
<br>
...<br>
<a href="http://105.170.72.0/24" rel="noreferrer" target="_blank">105.170.72.0/24</a> brs<br>
<a href="http://105.170.73.0/24" rel="noreferrer" target="_blank">105.170.73.0/24</a> brs<br>
<a href="http://105.170.74.0/24" rel="noreferrer" target="_blank">105.170.74.0/24</a> brs<br>
<a href="http://105.170.75.0/24" rel="noreferrer" target="_blank">105.170.75.0/24</a> brs<br>
<a href="http://105.170.76.0/24" rel="noreferrer" target="_blank">105.170.76.0/24</a> brs<br>
<a href="http://105.170.77.0/24" rel="noreferrer" target="_blank">105.170.77.0/24</a> brs<br>
<a href="http://105.170.78.0/24" rel="noreferrer" target="_blank">105.170.78.0/24</a> brs<br>
<a href="http://105.170.79.0/24" rel="noreferrer" target="_blank">105.170.79.0/24</a> brs<br>
<a href="http://105.170.80.0/24" rel="noreferrer" target="_blank">105.170.80.0/24</a> brs<br>
<a href="http://105.170.81.0/24" rel="noreferrer" target="_blank">105.170.81.0/24</a> brs<br>
<a href="http://105.170.82.0/24" rel="noreferrer" target="_blank">105.170.82.0/24</a> brs<br>
<a href="http://105.170.83.0/24" rel="noreferrer" target="_blank">105.170.83.0/24</a> brs<br>
<a href="http://105.170.84.0/24" rel="noreferrer" target="_blank">105.170.84.0/24</a> brs<br>
…<br>
<br>
and so on. Obviously, <a href="http://105.170.72.0/24" rel="noreferrer" target="_blank">105.170.72.0/24</a> thru <a href="http://105.170.79.0/24" rel="noreferrer" target="_blank">105.170.79.0/24</a> can be aggregated to <a href="http://105.170.72.0/21" rel="noreferrer" target="_blank">105.170.72.0/21</a> and so on. I normally use Perl, does anyone now if there is a perl module that will automatically do this prefix aggregation? I tried to write my code to do this, and its not trivial, just lookinh for a shortcurt. I did a breif glance at some CIDR related Perl cpan modules, and nothing has jumped out.<br>
<br>
Thanks<br>
John<br>
<br>
<br>
<br>
</blockquote></div>