nanog mailing list archives

Re: CIDR Utilization


From: Baldur Norddahl <baldur.norddahl () gmail com>
Date: Sun, 1 Nov 2015 00:01:52 +0100

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


Current thread: