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

Last change on this file since 906 was 906, checked in by Kris Deugau, 5 years ago

/trunk

Bulk addition of "add 'the directory the script is in' to @INC" for Perls
that have dropped '.' from @INC

  • Property svn:executable set to *
  • Property svn:keywords set to Date Rev Author
File size: 1.4 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: 2017-08-15 17:53:23 +0000 (Tue, 15 Aug 2017) $
7# SVN revision $Rev: 906 $
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
18# push "the directory the script is in" into @INC
19use FindBin;
20use lib "$FindBin::RealBin/";
21
22use MyIPDB;
23
24($dbh,$errstr) = connectDB_My;
25
26print "Content-type: text/plain\n\n";
27
28$tnumfree = $bigrfree = $bigufree = 0;
29
30$sql = 'select * from freeblocks where ';
31# General counts first
32if ($ARGV[0]) {
33  $sql .= 'maskbits >= $ARGV[0] and ';
34}
35$sql .= "not (cidr <<= '192.168.0.0/16') ".
36                "and not (cidr <<= '172.16.0.0/12') ".
37                "and not (cidr <<= '10.0.0.0/8') ";
38$sql .= "order by maskbits desc";
39
40$sth = $dbh->prepare($sql);
41$sth->execute;
42while (@data = $sth->fetchrow_array) {
43  # cidr,maskbits,city,routed
44  $tnumfree++;
45  $numfree{"$data[1]"}++;
46}
47
48print "Free block counts:\n";
49foreach $size (sort {$a cmp $b} keys %numfree) {
50  print "/$size: $numfree{$size}\n";
51}
52print "\n";
53
54for ($i=30; $i>16; $i--) {
55  $j = $i-1;
56  $numfree{"$j"} += int $numfree{"$i"}/2;
57  $numfree{"$i"} -= (int $numfree{"$i"}/2)*2;
58}
59
60print "Aggregate free space:\n";
61foreach $size (sort {$a cmp $b} keys %numfree) {
62  print "/$size: $numfree{$size}\n";
63}
Note: See TracBrowser for help on using the repository browser.