[15] | 1 | #!/usr/bin/perl
|
---|
| 2 | # -T
|
---|
| 3 | # ipdb/cgi-bin/extras/db2rwhois.pl
|
---|
[2] | 4 | # Pull data from ipdb and mangle it into RWHOIS
|
---|
[15] | 5 | # Initial version 03/26/2004 kdeugau against IPDB v1
|
---|
| 6 | ###
|
---|
| 7 | # Revision info
|
---|
| 8 | # $Date: 2005-06-17 20:42:45 +0000 (Fri, 17 Jun 2005) $
|
---|
| 9 | # SVN revision $Rev: 262 $
|
---|
| 10 | # Last update by $Author: kdeugau $
|
---|
| 11 | ###
|
---|
[146] | 12 | # Copyright (C) 2004,2005 - Kris Deugau
|
---|
[2] | 13 |
|
---|
[15] | 14 | use strict;
|
---|
| 15 | use warnings;
|
---|
[2] | 16 | use DBI;
|
---|
| 17 | use NetAddr::IP;
|
---|
[143] | 18 | use MyIPDB;
|
---|
[262] | 19 | use Digest::MD5 qw(md5_hex);
|
---|
[2] | 20 |
|
---|
| 21 | $ENV{"PATH"} = "/bin;/usr/bin";
|
---|
| 22 |
|
---|
[15] | 23 | my $rwhoisDataPath = "/etc/rwhoisd";
|
---|
| 24 |
|
---|
[2] | 25 | # We'll pull this out of the database instead. Just make sure our
|
---|
| 26 | # master blocks are actually listed.... <g>
|
---|
| 27 | #@masterblocks = (
|
---|
[15] | 28 | # (new NetAddr::IP "209.91.128.0/18"),
|
---|
| 29 | # (new NetAddr::IP "66.186.64.0/19"),
|
---|
| 30 | # (new NetAddr::IP "192.168.99.0/24")
|
---|
[2] | 31 | # );
|
---|
| 32 |
|
---|
[143] | 33 | my ($dbh,$msg) = connectDB_My;
|
---|
[2] | 34 |
|
---|
[143] | 35 | # For WHOIS purposes this may not be very useful. YMMV, we'll see.
|
---|
| 36 | #initIPDBGlobals($dbh);
|
---|
| 37 |
|
---|
[15] | 38 | my @masterblocks;
|
---|
| 39 |
|
---|
[2] | 40 | # Fill in data about our master blocks as allocated from ARIN
|
---|
| 41 | # We open separate files for each of these as appropriate.
|
---|
| 42 | # Note that this ASS-U-MEs that we do not add master IP blocks-
|
---|
| 43 | # there should probably be a separate system for doing that.
|
---|
[262] | 44 | my $sth = $dbh->prepare("select cidr,ctime from masterblocks;");
|
---|
[2] | 45 | $sth->execute;
|
---|
[15] | 46 | my $i=0;
|
---|
| 47 | GETMASTERS: while (my @data = $sth->fetchrow_array()) {
|
---|
[2] | 48 |
|
---|
[262] | 49 | # if ($data[0] =~ /^(192.168.0.0|172.16.0.0|10.0.0.0)/) {
|
---|
| 50 | # next GETMASTERS;
|
---|
| 51 | # }
|
---|
[15] | 52 | $masterblocks[$i] = new NetAddr::IP $data[0];
|
---|
[2] | 53 |
|
---|
[15] | 54 | print "$masterblocks[$i]\n";
|
---|
| 55 |
|
---|
| 56 | my $date;
|
---|
[2] | 57 | chomp ($date = `/bin/date +"%Y%m%d"`);
|
---|
[262] | 58 | my ($ctime,undef) = split /\s+/, $data[1];
|
---|
[2] | 59 |
|
---|
| 60 | # Whew! Ugly little varmint.
|
---|
[15] | 61 | my $masterfilename = "net-".$masterblocks[$i]->addr."-".$masterblocks[$i]->masklen.
|
---|
[2] | 62 | "/data/network/".$masterblocks[$i]->addr."-".$masterblocks[$i]->masklen.".txt";
|
---|
| 63 |
|
---|
[15] | 64 | # Need check here to create tree for netblock?
|
---|
[2] | 65 |
|
---|
[15] | 66 | open MASTERFILE,">$rwhoisDataPath/$masterfilename";
|
---|
| 67 |
|
---|
[2] | 68 | print MASTERFILE "ID: NETBLK-ISP.$masterblocks[$i]\n".
|
---|
| 69 | "Auth-Area: $masterblocks[$i]\n".
|
---|
| 70 | "Network-Name: ISP-".$masterblocks[$i]->network."\n".
|
---|
| 71 | "IP-Network: $masterblocks[$i]\n".
|
---|
| 72 | "IP-Network-Block: ".$masterblocks[$i]->range."\n".
|
---|
[15] | 73 | "Organization: Friendly ISP\n".
|
---|
| 74 | "Tech-Contact: noc\@example.com\n".
|
---|
[2] | 75 | "Admin-Contact: ISP-ARIN-HANDLE\n".
|
---|
[15] | 76 | "Abuse-Contact: abuse\@example.com\n".
|
---|
[262] | 77 | "Created: $ctime\n".
|
---|
[2] | 78 | "Updated: $date\n".
|
---|
| 79 | "Updated-By: noc\@example.com\n";
|
---|
| 80 |
|
---|
| 81 | close MASTERFILE;
|
---|
| 82 | $i++;
|
---|
| 83 | }
|
---|
| 84 |
|
---|
| 85 | # Now read out the data in the "main" delegation list, and check it
|
---|
| 86 | # with the master blocks. We need to do this to decide which rWHOIS
|
---|
| 87 | # "net-xxx.xxx.xxx.xxx-mask" tree the data belongs in.
|
---|
| 88 |
|
---|
[15] | 89 | # Make sure to remove the private netblocks from this.
|
---|
| 90 | # No use or point in broadcasting our use of them.
|
---|
[262] | 91 | #$sth = $dbh->prepare("select * from allocations where not (cidr <<= '192.168.0.0/16') and not (cidr <<= '172.16.0.0/12') and not (cidr <<= '10.0.0.0/8')");
|
---|
| 92 | # cidr,custid,type,city,description,notes,maskbits,circuitid,createstamp,modifystamp,newcustid
|
---|
| 93 |
|
---|
| 94 | $sth = $dbh->prepare("select cidr,custid,type,city,description,createstamp,modifystamp from allocations");
|
---|
[2] | 95 | $sth->execute;
|
---|
| 96 |
|
---|
[262] | 97 | while (my ($cidr,$custid,$type,$city,$description,$ctime,$mtime) = $sth->fetchrow_array()) {
|
---|
[2] | 98 |
|
---|
| 99 | # We get master block info from @masterblocks.
|
---|
| 100 | # ID: NETBLK-ISP.10.0.0.0/8
|
---|
| 101 | # Auth-Area: 10.0.0.0/8
|
---|
| 102 | # Network-Name: ISP-10.0.2.144
|
---|
| 103 | # IP-Network: 10.0.2.144.144/29
|
---|
| 104 | # IP-Network-Block: 10.0.2.144 - 10.0.2.151
|
---|
| 105 | # Organization: WidgetCorp
|
---|
| 106 | # Tech-Contact: bob@widgetcorp.com
|
---|
| 107 | # Admin-Contact: ISP-ARIN-HANDLE
|
---|
| 108 | # Created: 20040314
|
---|
| 109 | # Updated: 20040314
|
---|
| 110 | # Updated-By: noc@example.com
|
---|
| 111 |
|
---|
[262] | 112 | # Get the "full" network number - just in case.
|
---|
| 113 | my $net = new NetAddr::IP $cidr;
|
---|
[2] | 114 |
|
---|
| 115 | # Assumptions: All data in ipdb is public
|
---|
| 116 | # If not, we need another field to indicate "public/private".
|
---|
| 117 |
|
---|
[15] | 118 | foreach my $master (@masterblocks) {
|
---|
[2] | 119 | if ($master->contains($net)) {
|
---|
| 120 |
|
---|
| 121 | # Whew! Ugly little varmint.
|
---|
[15] | 122 | my $masterfilename = "net-".$master->addr."-".$master->masklen.
|
---|
[2] | 123 | "/data/network/".$master->addr."-".$master->masklen.".txt";
|
---|
| 124 |
|
---|
[15] | 125 | open MASTERFILE,">>$rwhoisDataPath/$masterfilename"
|
---|
| 126 | or print "File open error: '$!' on '$rwhoisDataPath/$masterfilename'\n";
|
---|
[2] | 127 |
|
---|
[15] | 128 | if ($data[4] =~ /^\s*$/) { $data[4] = 'Friendly ISP'; }
|
---|
[262] | 129 | print "$type-type $net for $custid, created $ctime, modified $mtime\n";
|
---|
[2] | 130 | print MASTERFILE "---\nID: NETBLK-ISP.$master\n".
|
---|
| 131 | "Auth-Area: $master\n".
|
---|
| 132 | "Network-Name: ISP-".$net->network."\n".
|
---|
| 133 | "IP-Network: $net\n".
|
---|
| 134 | "IP-Network-Block: ".$net->range."\n".
|
---|
[262] | 135 | "Organization: $description\n".
|
---|
[2] | 136 | # "Tech-Contact: $data[9]\n".
|
---|
| 137 | "Tech-Contact: abuse\@example.com\n".
|
---|
| 138 | "Admin-Contact: ISP-ARIN-HANDLE\n".
|
---|
[262] | 139 | "Created: $ctime\n".
|
---|
| 140 | "Updated: $mtime\n".
|
---|
[2] | 141 | "Updated-By: noc\@example.com\n";
|
---|
| 142 | }
|
---|
| 143 | }
|
---|
| 144 |
|
---|
| 145 |
|
---|
| 146 |
|
---|
| 147 | # print "$data[0]\t| $data[1]\t| $data[2]\t| $data[3]\t| $data[4]\t| ".
|
---|
| 148 | # "$data[5]\t| $data[6]\t| $data[7]\t| $data[8]\t| $data[9]\n";
|
---|
| 149 | # print "$data[0]\t| $data[1]\t| $data[2]\t| $data[3]\t| $data[4]\t| ".
|
---|
| 150 | # "$data[5]\t| $data[6]\t| $data[7]\t| $data[8]\n";
|
---|
| 151 |
|
---|
| 152 | } # while fetchrow_array()
|
---|
| 153 |
|
---|
| 154 |
|
---|
| 155 | $dbh->disconnect;
|
---|
[262] | 156 |
|
---|
| 157 | # This doesn't work, with a vengeance.
|
---|
| 158 | #print qx{ /usr/bin/rwhois_indexer -c /etc/rwhoisd/rwhoisd.conf -i -v -s txt };
|
---|