Changeset 15 for trunk/cgi-bin
- Timestamp:
- 10/25/04 17:32:05 (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/cgi-bin/extras/db2rwhois.pl
r2 r15 1 #!/usr/bin/perl -W -T 2 # db2rwhois.pl 1 #!/usr/bin/perl 2 # -T 3 # ipdb/cgi-bin/extras/db2rwhois.pl 3 4 # Pull data from ipdb and mangle it into RWHOIS 4 # Initial version 03/26/2004 kdeugau 5 # Initial version 03/26/2004 kdeugau against IPDB v1 6 ### 7 # Revision info 8 # $Date$ 9 # SVN revision $Rev$ 10 # Last update by $Author$ 11 ### 5 12 13 use strict; 14 use warnings; 6 15 use DBI; 7 16 use NetAddr::IP; 17 use IPDB qw(:ALL); 8 18 9 19 $ENV{"PATH"} = "/bin;/usr/bin"; 20 21 my $rwhoisDataPath = "/etc/rwhoisd"; 10 22 11 23 # We'll pull this out of the database instead. Just make sure our 12 24 # master blocks are actually listed.... <g> 13 25 #@masterblocks = ( 14 # (new NetAddr::IP " 10.0.0.0/8"),15 # (new NetAddr::IP " 172.16.0.0/12"),16 # (new NetAddr::IP "192.168. 0.0/16")26 # (new NetAddr::IP "209.91.128.0/18"), 27 # (new NetAddr::IP "66.186.64.0/19"), 28 # (new NetAddr::IP "192.168.99.0/24") 17 29 # ); 18 30 19 $dbh = DBI->connect("dbi:mysql:ipdb", "root", "") 20 or die $DBI::errstr; 31 my $dbh = connectDB; 32 33 my @masterblocks; 21 34 22 35 # Fill in data about our master blocks as allocated from ARIN … … 24 37 # Note that this ASS-U-MEs that we do not add master IP blocks- 25 38 # there should probably be a separate system for doing that. 26 $sth = $dbh->prepare("select * from masterblocks;");39 my $sth = $dbh->prepare("select * from masterblocks;"); 27 40 $sth->execute; 28 $i=0; 29 while (@data = $sth->fetchrow_array()) { 30 # Get the "full" network number+CIDR mask 31 $cidr = $data[0].".".$data[2].$data[1]; 41 my $i=0; 42 GETMASTERS: while (my @data = $sth->fetchrow_array()) { 32 43 33 $masterblocks[$i] = new NetAddr::IP $cidr; 44 if ($data[0] =~ /^(192.168.0.0|172.16.0.0|10.0.0.0)/) { 45 next GETMASTERS; 46 } 47 $masterblocks[$i] = new NetAddr::IP $data[0]; 34 48 49 print "$masterblocks[$i]\n"; 50 51 my $date; 35 52 chomp ($date = `/bin/date +"%Y%m%d"`); 36 53 37 54 # Whew! Ugly little varmint. 38 $masterfilename = "net-".$masterblocks[$i]->addr."-".$masterblocks[$i]->masklen.55 my $masterfilename = "net-".$masterblocks[$i]->addr."-".$masterblocks[$i]->masklen. 39 56 "/data/network/".$masterblocks[$i]->addr."-".$masterblocks[$i]->masklen.".txt"; 40 57 41 open MASTERFILE,">$masterfilename"; 58 # Need check here to create tree for netblock? 59 60 open MASTERFILE,">$rwhoisDataPath/$masterfilename"; 42 61 43 62 print MASTERFILE "ID: NETBLK-ISP.$masterblocks[$i]\n". … … 46 65 "IP-Network: $masterblocks[$i]\n". 47 66 "IP-Network-Block: ".$masterblocks[$i]->range."\n". 48 "Organization: $data[3]\n".49 "Tech-Contact: $data[9]\n".67 "Organization: Friendly ISP\n". 68 "Tech-Contact: noc\@example.com\n". 50 69 "Admin-Contact: ISP-ARIN-HANDLE\n". 51 "Created: 20040401000000000\n". 70 "Abuse-Contact: abuse\@example.com\n". 71 "Created: 20040308\n". 52 72 "Updated: $date\n". 53 73 "Updated-By: noc\@example.com\n"; … … 61 81 # "net-xxx.xxx.xxx.xxx-mask" tree the data belongs in. 62 82 63 #$sth = $dbh->prepare("select * from blocks;"); 64 $sth = $dbh->prepare("select * from tmpblocks;"); 83 # Make sure to remove the private netblocks from this. 84 # No use or point in broadcasting our use of them. 85 $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') and custid='6750400'"); 65 86 $sth->execute; 66 87 67 while ( @data = $sth->fetchrow_array()) {88 while (my @data = $sth->fetchrow_array()) { 68 89 69 90 # We get master block info from @masterblocks. … … 81 102 82 103 # Get the "full" network number 83 $netnum = $data[0].".".$data[2]; 84 85 $cidr = $netnum.$data[1]; 86 87 $net = new NetAddr::IP $cidr; 104 my $net = new NetAddr::IP $data[0]; 88 105 89 106 # Assumptions: All data in ipdb is public 90 107 # If not, we need another field to indicate "public/private". 91 108 92 foreach $master (@masterblocks) {109 foreach my $master (@masterblocks) { 93 110 if ($master->contains($net)) { 94 111 95 112 # Whew! Ugly little varmint. 96 $masterfilename = "net-".$master->addr."-".$master->masklen.113 my $masterfilename = "net-".$master->addr."-".$master->masklen. 97 114 "/data/network/".$master->addr."-".$master->masklen.".txt"; 98 115 99 open MASTERFILE,">>$masterfilename"; 116 open MASTERFILE,">>$rwhoisDataPath/$masterfilename" 117 or print "File open error: '$!' on '$rwhoisDataPath/$masterfilename'\n"; 100 118 119 # cidr custid type city description notes maskbits 120 121 # Creation date in record to eventually be "correct"; near-term will 122 # be master's creation date; immediate is today's date. 123 my $date; 101 124 chomp ($date = `/bin/date +"%Y%m%d"`); 125 if ($data[4] =~ /^\s*$/) { $data[4] = 'Friendly ISP'; } 102 126 print MASTERFILE "---\nID: NETBLK-ISP.$master\n". 103 127 "Auth-Area: $master\n". … … 105 129 "IP-Network: $net\n". 106 130 "IP-Network-Block: ".$net->range."\n". 107 "Organization: $data[ 5]\n".131 "Organization: $data[4]\n". 108 132 # "Tech-Contact: $data[9]\n". 109 133 "Tech-Contact: abuse\@example.com\n". 110 134 "Admin-Contact: ISP-ARIN-HANDLE\n". 111 "Created: <date from db> (or today's date?)\n".135 "Created: $date\n". 112 136 "Updated: $date\n". 113 137 "Updated-By: noc\@example.com\n";
Note:
See TracChangeset
for help on using the changeset viewer.