source: trunk/cgi-bin/freespace.pl@ 417

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

/trunk

Rearrangements and tweaks toward releaseability:

  • Add Makefile to install halfway-sanely
  • Add .spec file
  • Shuffle "use IPDB;" and "use MyIPDB;" lines so that we can automagically insert a suitable "use lib..." line during 'make install'
  • Check copyright statements
  • Clear up some defaults, and place a number of "constants" in IPDB/MyIPDB rather than having them hardcoded all over the place (Still need to think of a sane way to do this for ipdb.psql's alloctype preseeding)
  • Tweak $VERSION identifier in IPDB.pm so it can be defined in the Makefile
  • Clean up some dangling bits from repository history conversion, remove unneeded "use ..." statements
  • Tweak rWHOIS export script to use more globals and "constants" from (My)IPDB.pm, and more Perl internals than system()-equivalents. Add a few fixme comments for longer-term flexibility improvements.
  • 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-06-30 21:48:03 +0000 (Wed, 30 Jun 2010) $
7# SVN revision $Rev: 417 $
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.