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

Last change on this file since 121 was 117, checked in by Kris Deugau, 20 years ago

/branches/stable

Added freespace.pl free-space-stats generator

  • Property svn:executable set to *
  • Property svn:keywords set to Date Rev Author
File size: 1.0 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: 2005-01-06 16:14:21 +0000 (Thu, 06 Jan 2005) $
7# SVN revision $Rev: 117 $
8# Last update by $Author: kdeugau $
9###
10
11use DBI;
12use IPDB qw(:ALL);
13use NetAddr::IP;
14
15$dbh = connectDB;
16
17print "Content-type: text/plain\n\n";
18
19$tnumfree = $bigrfree = $bigufree = 0;
20
21# General counts first
22if ($ARGV[0]) {
23 $sth = $dbh->prepare("select * from freeblocks where maskbits >= $ARGV[0] order by maskbits desc");
24} else {
25 $sth = $dbh->prepare("select * from freeblocks order by maskbits desc");
26}
27$sth->execute;
28while (@data = $sth->fetchrow_array) {
29 # cidr,maskbits,city,routed
30 $tnumfree++;
31 $numfree{"$data[1]"}++;
32}
33
34foreach $size (sort {$a cmp $b} keys %numfree) {
35 print "/$size: $numfree{$size}\n";
36}
37print "\n";
38
39for ($i=30; $i>16; $i--) {
40 $j = $i-1;
41 $numfree{"$j"} += int $numfree{"$i"}/2;
42 $numfree{"$i"} -= (int $numfree{"$i"}/2)*2;
43}
44
45foreach $size (sort {$a cmp $b} keys %numfree) {
46 print "/$size: $numfree{$size}\n";
47}
Note: See TracBrowser for help on using the repository browser.