Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 2 Dec 2019 12:02:23 +0000
From:      Matthew Seaman <matthew@FreeBSD.org>
To:        freebsd-questions@freebsd.org
Subject:   Re: Network Aggregation
Message-ID:  <6d5f214c-0f40-50d0-8cf7-b5954c18e266@FreeBSD.org>
In-Reply-To: <20191202060719.000059a1@seibercom.net>
References:  <20191202060719.000059a1@seibercom.net>

next in thread | previous in thread | raw e-mail | index | archive | help
This is an OpenPGP/MIME signed message (RFC 4880 and 3156)
--EermoEqdCEHxB2EUS84HbImN0pZBX0IWP
Content-Type: multipart/mixed; boundary="QxTCuHX33Jf0KbQKtGpFG9R0MfDdOR9Ps"

--QxTCuHX33Jf0KbQKtGpFG9R0MfDdOR9Ps
Content-Type: text/plain; charset=utf-8
Content-Language: en-GB
Content-Transfer-Encoding: quoted-printable

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:

=3D> 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)

=3D> 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#spannin=
g_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






--QxTCuHX33Jf0KbQKtGpFG9R0MfDdOR9Ps--

--EermoEqdCEHxB2EUS84HbImN0pZBX0IWP
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="signature.asc"

-----BEGIN PGP SIGNATURE-----

iQKTBAEBCgB9FiEEGfFU7L8RLlBUTj8wAFE/EOCp5OcFAl3k/U9fFIAAAAAALgAo
aXNzdWVyLWZwckBub3RhdGlvbnMub3BlbnBncC5maWZ0aGhvcnNlbWFuLm5ldDE5
RjE1NEVDQkYxMTJFNTA1NDRFM0YzMDAwNTEzRjEwRTBBOUU0RTcACgkQAFE/EOCp
5OdNkg//ei4C4t/pgp47do+ecKODu2Mu0QvQiExY8Jxfw6hLxoqryCa1eDdz9FUC
Ab4F6qoWXMyPwqaVoP7PnW1sIqnpVRBPo7jIohkdKc7eNeRBcrfx5M4xQ9vWqxjA
f3UGQkI3g57qKqmuhax9BiXE/Aky/KbPxCu5APfWh9B0s39b++NQjfHwT4jWXpER
CFfSUYsoiuljCs5vZkeIKMUJDbsy8oXHqFIZda2QinkEPTWBprZA4vXc4c/uRMED
XwiymikWxjCrEOo60biNnMM0sAoYgMXosYllEkgJqGtdnssmCOCkU8i6EegKHXtC
bJPzywsXtyQ5W/fuaDmGIBmcKuKzrIsOzEOHdHYepeaA+0J2psBcuJlVBBrvQwXO
B28JHNKYgwPnzmxmVaJmXNn5i+001dtM121nTKV8QI0K6Wvop22eidRAiWmqP8yK
UROp2z9ZRzFWahj7OFJ+seR7/8ny+smtdfVtjCKavh88G/+vhLrYrhRflNzwW61P
4YCb5mgCin2RzoqhuQeHhjhJxT7LzSb6opb+mfFVMpgF2ufTej7NznpmISC0Pq7x
NlnlUuNDVezev5qDEEmXa3gvPmGUc5MQ5SgQdiROp7k29FRaTdUyuDQWdQrJkfGJ
DMPIUbwfnSEfv84TJDPpJ/Ux2aGUUq2Q2Prf9NtZvs2ceJfFSAc=
=yn5a
-----END PGP SIGNATURE-----

--EermoEqdCEHxB2EUS84HbImN0pZBX0IWP--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?6d5f214c-0f40-50d0-8cf7-b5954c18e266>