source: trunk/cgi-bin/import2.pl@ 6

Last change on this file since 6 was 6, checked in by Kris Deugau, 20 years ago

Add intermediate development files for posterity

  • Property svn:executable set to *
File size: 1.8 KB
Line 
1#!/usr/bin/perl
2# Import data from old IPDB to new DB
3# Started 06/29/04 kdeugau@vianet
4
5#use warnings;
6#use CGI::Carp qw/fatalsToBrowser/;
7use DBI;
8#use DBD::Pg;
9#use CommonWeb qw/:ALL/;
10#use POSIX qw/ceil/;
11use NetAddr::IP;
12
13#use strict;
14
15$null = new NetAddr::IP "255.255.255.255/32";
16
17# Hardcode the masters because it's too messy and slow to
18# snag them programmatically *EVERY TIME*
19@masters = ((new NetAddr::IP "66.186.64.0/19"),
20 (new NetAddr::IP "204.138.172.0/24"),
21 (new NetAddr::IP "204.187.88.0/23"),
22 (new NetAddr::IP "205.207.184.0/23"),
23 (new NetAddr::IP "206.130.64.0/24"),
24 (new NetAddr::IP "209.91.128.0/18"),
25 (new NetAddr::IP "10.0.0.0/8"),
26 (new NetAddr::IP "192.168.0.0/16"),
27 );
28
29# First step: Slurp up data to find "master" blocks
30 my $DSN = "DBI:mysql:ipdb";
31 my $user = 'root';
32 my $pw = '';
33 $dbh = DBI->connect($DSN, $user, $pw) || return undef if(!$dbh);
34
35$newdbh = DBI->connect("DBI:Pg:dbname=ipdb", "ipdb", "");
36
37$i=0;
38$sth = $dbh->prepare("select * from blocks where netmask !='/32' and netmask !='/31'");
39$sth->execute;
40CIDR: while (@data = $sth->fetchrow_array) {
41 # data contains ipclass,netmask,subnet,city,custid,name,swip,description,notes
42 $cidr = new NetAddr::IP "$data[0].$data[2]$data[1]";
43 $sth2 = $newdbh->prepare("select count(*) from allocations where cidr='$cidr'");
44 $sth2->execute;
45if ($sth2->err) { print "err on $cidr ($data[4], $data[5]): ".$sth2->errstr."\n"; }
46 @data = $sth2->fetchrow_array;
47 if ($data[0] ne '1') {
48 print "$cidr not found in allocations";
49 $sth2 = $newdbh->prepare("select count(*) from freeblocks where cidr='$cidr'");
50 $sth2->execute;
51 @data = $sth2->fetchrow_array;
52 if ($data[0] eq '1') {
53 print "\t...but found in freeblocks.\n";
54 } else {
55 print "\t...and not found in freeblocks.\n";
56 }
57 }
58 $i++;
59}
Note: See TracBrowser for help on using the repository browser.