1 | #!/usr/bin/perl
|
---|
2 | # ipdb/cgi-bin/freespace.pl
|
---|
3 | # Quick hack to calculate aggregate free IP space, and statistic-ify the blocks.
|
---|
4 | ###
|
---|
5 | # SVN revision info
|
---|
6 | # $Date: 2006-01-19 17:15:52 +0000 (Thu, 19 Jan 2006) $
|
---|
7 | # SVN revision $Rev: 305 $
|
---|
8 | # Last update by $Author: kdeugau $
|
---|
9 | ###
|
---|
10 | # Copyright (C) 2004,2005 - Kris Deugau
|
---|
11 |
|
---|
12 | use DBI;
|
---|
13 | use MyIPDB;
|
---|
14 | use NetAddr::IP;
|
---|
15 |
|
---|
16 | ($dbh,$errstr) = connectDB_My;
|
---|
17 |
|
---|
18 | print "Content-type: text/plain\n\n";
|
---|
19 |
|
---|
20 | $tnumfree = $bigrfree = $bigufree = 0;
|
---|
21 |
|
---|
22 | # General counts first
|
---|
23 | if ($ARGV[0]) {
|
---|
24 | $sth = $dbh->prepare("select * from freeblocks where maskbits >= $ARGV[0] order by maskbits desc");
|
---|
25 | } else {
|
---|
26 | $sth = $dbh->prepare("select * from freeblocks order by maskbits desc");
|
---|
27 | }
|
---|
28 | $sth->execute;
|
---|
29 | while (@data = $sth->fetchrow_array) {
|
---|
30 | # cidr,maskbits,city,routed
|
---|
31 | next if $data[0] =~ /^10\./;
|
---|
32 | #next if $data[0] =~ /^172\.16\./;
|
---|
33 | next if $data[0] =~ /^192\.168\./;
|
---|
34 | $tnumfree++;
|
---|
35 | $numfree{"$data[1]"}++;
|
---|
36 | }
|
---|
37 |
|
---|
38 | foreach $size (sort {$a cmp $b} keys %numfree) {
|
---|
39 | print "/$size: $numfree{$size}\n";
|
---|
40 | }
|
---|
41 | print "\n";
|
---|
42 |
|
---|
43 | for ($i=30; $i>16; $i--) {
|
---|
44 | $j = $i-1;
|
---|
45 | $numfree{"$j"} += int $numfree{"$i"}/2;
|
---|
46 | $numfree{"$i"} -= (int $numfree{"$i"}/2)*2;
|
---|
47 | }
|
---|
48 |
|
---|
49 | foreach $size (sort {$a cmp $b} keys %numfree) {
|
---|
50 | print "/$size: $numfree{$size}\n";
|
---|
51 | }
|
---|