Network Aggregation

Jerry jerry at seibercom.net
Mon Dec 2 12:06:45 UTC 2019


On Mon, 2 Dec 2019 12:02:23 +0000, Matthew Seaman commented:
>On 02/12/2019 11:07, Jerry wrote:
>> I am looking for a program that will automate combining IP addresses,
>> usually referred to as aggregation. I have been doing it by hand, and
>> it is a real PIA.  
>
>As in: take a list of IP numbers and output the smallest netblock
>(network address, netmask) that will contain them all?
>
>If you want a graphical approach, than most IP Address Managment
>applications will pretty much do this.  Try Netbox for instance:
>
>   https://netbox.readthedocs.io/en/stable/
>
>In ports as net-mgmt/netbox.
>
>Although netbox itself depends on the ip address data types provided by
>postgresql:
>
>   https://www.postgresql.org/docs/11/datatype-net-types.html
>   https://www.postgresql.org/docs/11/functions-net.html
>
>which suggests that reading your list of ip numbers into a table, and
>then calling inet_merge() on the minimum and maximum values will give
>you what you want.  Something like:
>
>   CREATE TABLE ip_numbers ( ip inet );
>   INSERT INTO ip_numbers (ip) VALUES ('192.168.1.1/32'),
>'192.168.1.3/32'), ('192.168.24.234/32'),('192.168.63.1/32') ;
>
>Then:
>
>=> SELECT * FROM ip_numbers ORDER BY ip;  
>       ip
>----------------
> 192.168.1.1
> 192.168.1.3
> 192.168.24.234
> 192.168.63.1
>(4 rows)
>
>=> SELECT inet_merge(MIN(ip), MAX(ip)) FROM ip_numbers ;  
>   inet_merge
>----------------
> 192.168.0.0/18
>(1 row)
>
>If you want a more scripted approach, then I'd turn to the netaddr
>module in Python: https://netaddr.readthedocs.io/en/latest/ --
>specifically this method:
>
>https://netaddr.readthedocs.io/en/latest/_modules/netaddr/ip.html#spanning_cidr
>
>but writing a very small script to apply that to a list of addresses is
>left as an exercise for the student...
>
>	Cheers,
>
>	Matthew

Thanks, Matthew. I will give them a try.

-- 
Jerry



-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <http://lists.freebsd.org/pipermail/freebsd-questions/attachments/20191202/255ce50c/attachment.sig>


More information about the freebsd-questions mailing list