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

Last change on this file since 939 was 906, checked in by Kris Deugau, 7 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
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: 2017-08-15 17:53:23 +0000 (Tue, 15 Aug 2017) $
7# SVN revision $Rev: 906 $
8# Last update by $Author: kdeugau $
9###
[417]10# Copyright (C) 2004-2010 - Kris Deugau
[117]11
12use DBI;
13use NetAddr::IP;
14
[417]15# don't remove! required for GNU/FHS-ish install from tarball
16##uselib##
17
[906]18# push "the directory the script is in" into @INC
19use FindBin;
20use lib "$FindBin::RealBin/";
21
[417]22use MyIPDB;
23
[142]24($dbh,$errstr) = connectDB_My;
[117]25
26print "Content-type: text/plain\n\n";
27
28$tnumfree = $bigrfree = $bigufree = 0;
29
[320]30$sql = 'select * from freeblocks where ';
[117]31# General counts first
32if ($ARGV[0]) {
[320]33 $sql .= 'maskbits >= $ARGV[0] and ';
[117]34}
[320]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);
[117]41$sth->execute;
42while (@data = $sth->fetchrow_array) {
43 # cidr,maskbits,city,routed
44 $tnumfree++;
45 $numfree{"$data[1]"}++;
46}
47
[320]48print "Free block counts:\n";
[117]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
[320]60print "Aggregate free space:\n";
[117]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.