source: trunk/cgi-bin/combineblocks.pl@ 948

Last change on this file since 948 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.7 KB
Line 
1#!/usr/bin/perl
2# ipdb/cgi-bin/combineblocks.pl
3# Quick hack to clean up mangled deallocations
4###
5# 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
11use strict;
12use warnings;
13#use CGI::Carp qw(fatalsToBrowser);
14use DBI;
15#use POSIX qw(ceil);
16use NetAddr::IP;
17
18# don't remove! required for GNU/FHS-ish install from tarball
19##uselib##
20
21# push "the directory the script is in" into @INC
22use FindBin;
23use lib "$FindBin::RealBin/";
24
25use MyIPDB;
26
27my $null = new NetAddr::IP "255.255.255.255/32";
28
29my @fbtypes;
30
31my ($dbh,$ret) = connectDB_My;
32initIPDBGlobals($dbh);
33my $sth;
34
35# Get the types of freeblocks
36$sth = $dbh->prepare("select distinct routed from freeblocks");
37$sth->execute;
38while (my @data = $sth->fetchrow_array) {
39 push @fbtypes, @data;
40}
41
42foreach my $type (@fbtypes) {
43
44 my $i=0;
45 my @compacted;
46
47 my $sth = $dbh->prepare("select cidr from freeblocks where routed='$type'");
48 $sth->execute;
49 while (my @data = $sth->fetchrow_array) {
50 my $temp = new NetAddr::IP $data[0];
51 @compacted = $temp->compact(@compacted);
52 $i++;
53 }
54
55#print $compacted[0];
56my $numcomp = @compacted;
57#print " $numcomp";
58
59 if ($i == $numcomp) {
60 print "No compactable blocks for type $type ($i free)\n";
61 next;
62 }
63 print "Type $type: $i free blocks to start, $numcomp to finish\n";
64
65 $sth = $dbh->prepare("select cidr from freeblocks where cidr << ?");
66 foreach my $cip (@compacted) {
67 $sth->execute("$cip");
68 if ($sth->rows > 0) {
69 print " $cip combines from:\n";
70 while (my @data = $sth->fetchrow_array) {
71 print " $data[0]\n";
72 }
73# } else {
74# print " $cip does not compact\n";
75 }
76 }
77
78} # each @fbtype
79
80finish($dbh);
Note: See TracBrowser for help on using the repository browser.