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

Last change on this file since 471 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
RevLine 
[117]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###
[445]10# Copyright (C) 2004-2010 - Kris Deugau
[117]11
12use DBI;
13use NetAddr::IP;
14
[445]15# don't remove! required for GNU/FHS-ish install from tarball
16##uselib##
17
18use MyIPDB;
19
[158]20($dbh,$errstr) = connectDB_My;
[117]21
22print "Content-type: text/plain\n\n";
23
24$tnumfree = $bigrfree = $bigufree = 0;
25
[317]26$sql = 'select * from freeblocks where ';
[117]27# General counts first
28if ($ARGV[0]) {
[317]29 $sql .= 'maskbits >= $ARGV[0] and ';
[117]30}
[317]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);
[117]37$sth->execute;
38while (@data = $sth->fetchrow_array) {
39 # cidr,maskbits,city,routed
40 $tnumfree++;
41 $numfree{"$data[1]"}++;
42}
43
[319]44print "Free block counts:\n";
[117]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
[319]56print "Aggregate free space:\n";
[117]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.