[185627] in North American Network Operators' Group

home help back first fref pref prev next nref lref last post

Re: CIDR Utilization

daemon@ATHENA.MIT.EDU (Baldur Norddahl)
Sat Oct 31 19:02:00 2015

X-Original-To: nanog@nanog.org
In-Reply-To: <CA+OqHhABBFK6YQ9nQCRfOvP58maV5Kx4wj3oYPpFWrDyJDcapg@mail.gmail.com>
Date: Sun, 1 Nov 2015 00:01:52 +0100
From: Baldur Norddahl <baldur.norddahl@gmail.com>
To: "nanog@nanog.org" <nanog@nanog.org>
Errors-To: nanog-bounces@nanog.org

On 31 October 2015 at 01:51, John Steve Nash <john.steve.nash@gmail.com>
wrote:

> I'm looking for any tool or a way I could specify a CIDR and the prefixes
> that are being used within this CIDR and the tool show me all free
> supernets.
>

For the weekend exercise I wrote a small script that does this. You can
find it at http://pastebin.com/i0D54Lsq

Usage:

cat input.txt | ./subnet.sh

The input.txt file contains your input such as:

Baldurs-MBP-2:~ baldur$ cat /tmp/x
add 192.168.0.0/24
remove 192.168.0.1/32
remove 192.168.0.8/27
remove 192.168.0.64/26
remove 192.168.0.68/32
remove 192.168.0.96/29

Baldurs-MBP-2:~ baldur$ cat /tmp/x | ./subnet.sh
192.168.0.32/27
192.168.0.128/25

Note this was not your expected output, but that is because your example is
defective. To get your expected output we can modify the input such as:

Baldurs-MBP-2:~ baldur$ cat /tmp/x
add 192.168.0.0/24
remove 192.168.0.0/31
remove 192.168.0.3/32
remove 192.168.0.8/29
remove 192.168.0.16/28
remove 192.168.0.64/26
remove 192.168.0.68/32
remove 192.168.0.96/29

Baldurs-MBP-2:~ baldur$ cat /tmp/x | ./subnet.sh
192.168.0.2/32
192.168.0.4/30
192.168.0.32/27
192.168.0.128/25

You can have multiple add lines and add/remove lines in any order.

Regards,

Baldur

home help back first fref pref prev next nref lref last post