source: branches/stable/cgi-bin/freespace.pl@ 317

Last change on this file since 317 was 317, checked in by Kris Deugau, 19 years ago

/branches/stable

freespace.pl fixup; more cleanly remove private netblocks.

  • Property svn:executable set to *
  • Property svn:keywords set to Date Rev Author
File size: 1.1 KB
Line 
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-03-31 22:01:56 +0000 (Fri, 31 Mar 2006) $
7# SVN revision $Rev: 317 $
8# Last update by $Author: kdeugau $
9###
10# Copyright (C) 2004,2005 - Kris Deugau
11
12use DBI;
13use MyIPDB;
14use NetAddr::IP;
15
16($dbh,$errstr) = connectDB_My;
17
18print "Content-type: text/plain\n\n";
19
20$tnumfree = $bigrfree = $bigufree = 0;
21
22$sql = 'select * from freeblocks where ';
23# General counts first
24if ($ARGV[0]) {
25 $sql .= 'maskbits >= $ARGV[0] and ';
26}
27$sql .= "not (cidr <<= '192.168.0.0/16') ".
28 "and not (cidr <<= '172.16.0.0/12') ".
29 "and not (cidr <<= '10.0.0.0/8') ";
30$sql .= "order by maskbits desc";
31
32$sth = $dbh->prepare($sql);
33$sth->execute;
34while (@data = $sth->fetchrow_array) {
35 # cidr,maskbits,city,routed
36 $tnumfree++;
37 $numfree{"$data[1]"}++;
38}
39
40foreach $size (sort {$a cmp $b} keys %numfree) {
41 print "/$size: $numfree{$size}\n";
42}
43print "\n";
44
45for ($i=30; $i>16; $i--) {
46 $j = $i-1;
47 $numfree{"$j"} += int $numfree{"$i"}/2;
48 $numfree{"$i"} -= (int $numfree{"$i"}/2)*2;
49}
50
51foreach $size (sort {$a cmp $b} keys %numfree) {
52 print "/$size: $numfree{$size}\n";
53}
Note: See TracBrowser for help on using the repository browser.