Date: Mon, 2 Dec 2019 07:06:32 -0500 From: Jerry <jerry@seibercom.net> To: freebsd-questions@freebsd.org Subject: Re: Network Aggregation Message-ID: <20191202070632.00006110@seibercom.net> In-Reply-To: <6d5f214c-0f40-50d0-8cf7-b5954c18e266@FreeBSD.org> References: <20191202060719.000059a1@seibercom.net> <6d5f214c-0f40-50d0-8cf7-b5954c18e266@FreeBSD.org>
next in thread | previous in thread | raw e-mail | index | archive | help
--Sig_/70ydY5=lhCpEjkNFbyEZQCh Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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. =20 > >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: > >=3D> SELECT * FROM ip_numbers ORDER BY ip; =20 > ip >---------------- > 192.168.1.1 > 192.168.1.3 > 192.168.24.234 > 192.168.63.1 >(4 rows) > >=3D> SELECT inet_merge(MIN(ip), MAX(ip)) FROM ip_numbers ; =20 > 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. --=20 Jerry --Sig_/70ydY5=lhCpEjkNFbyEZQCh Content-Type: application/pgp-signature Content-Description: OpenPGP digital signature -----BEGIN PGP SIGNATURE----- iQEzBAEBCAAdFiEEIQb/tTwl6I1ueEVtOHMGOIfexWQFAl3k/kgACgkQOHMGOIfe xWQ8DggAuc4VFMjYYmU5iUS8HmyaVfLKtiy3ufyEeP9fFtG1RKPkJXbdSWAe9IMm FwNMl4+jjVPeVWuAyvEM4S8oqJI6VR7IM3ewniZ4hiJJVMkSbLx338IJ/ETCkkiu bQDxq/E9GUC8RxbCD33O44rgpsvgwtNWxUyY2NzcMWaRtTr0sEeaKfToWn4pUeIn 8obR1c4jsFQyGJoDHkuDI86YqQi2FkYkbU4N9T2gk+L7YaEGFpK5FoC4Odz8DtRH LOsXv3rHkL+ppHynkjwS+jj5iXs9i6Oj14/c8mgH9PXMk7hcu61Qedn4S3aZkmiD Iqaq87fo7x6UV8dd+u92MdVTawTEoA== =bh6b -----END PGP SIGNATURE----- --Sig_/70ydY5=lhCpEjkNFbyEZQCh--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20191202070632.00006110>