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

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

/branches/stable

Remove private 10.* and 192.168.* subnets from counts in freespace.pl

  • Property svn:executable set to *
  • Property svn:keywords set to Date Rev Author
File size: 1.2 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-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
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# General counts first
23if ($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;
29while (@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
38foreach $size (sort {$a cmp $b} keys %numfree) {
39 print "/$size: $numfree{$size}\n";
40}
41print "\n";
42
43for ($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
49foreach $size (sort {$a cmp $b} keys %numfree) {
50 print "/$size: $numfree{$size}\n";
51}
Note: See TracBrowser for help on using the repository browser.