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

Last change on this file since 613 was 445, checked in by Kris Deugau, 14 years ago

/branches/stable

Bring /branches/stable up to date with /trunk. See #13.

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