Changeset 311 for trunk/cgi-bin/extras
- Timestamp:
- 03/28/06 15:27:06 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/cgi-bin/extras/db2rwhois.pl
r218 r311 17 17 use NetAddr::IP; 18 18 use MyIPDB; 19 use Digest::MD5 qw(md5_hex);20 19 21 20 $ENV{"PATH"} = "/bin;/usr/bin"; 22 21 23 22 my $rwhoisDataPath = "/etc/rwhoisd"; 24 25 # We'll pull this out of the database instead. Just make sure our26 # master blocks are actually listed.... <g>27 #@masterblocks = (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")31 # );32 23 33 24 my ($dbh,$msg) = connectDB_My; … … 47 38 GETMASTERS: while (my @data = $sth->fetchrow_array()) { 48 39 49 # if ($data[0] =~ /^(192.168.0.0|172.16.0.0|10.0.0.0)/) { 50 # next GETMASTERS; 51 # } 40 # Techically, we only need to exclude 204.138.172.0/24, as we "own" all of the other blocks. 41 # However, 205.207.184.0/23 and 206.130.64.0/24 are, um, awkward. 42 if ($data[0] =~ /^(192.168.0.0|172.16.0.0|10.0.0.0|20[456])/) { 43 next GETMASTERS; 44 } 52 45 $masterblocks[$i] = new NetAddr::IP $data[0]; 46 my ($ctime,undef) = split /\s/, $data[1]; 53 47 54 print "$masterblocks[$i] \n";48 print "$masterblocks[$i] $data[1]\n"; 55 49 56 50 my $date; 57 chomp ($date = `/bin/date +"%Y%m%d"`); 58 my ($ctime,undef) = split /\s+/, $data[1]; 51 chomp ($date = `/bin/date +"%Y-%m-%d"`); 59 52 60 53 # Whew! Ugly little varmint. … … 89 82 # Make sure to remove the private netblocks from this. 90 83 # No use or point in broadcasting our use of them. 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"); 84 # Also remove the details of our "reserved CORE/WAN" blocks; they're not critical. 85 $sth = $dbh->prepare("select cidr,custid,type,city,description,createstamp,modifystamp ". 86 "from allocations where ". 87 "not (cidr <<= '192.168.0.0/16') and ". 88 "not (cidr <<= '172.16.0.0/12') and ". 89 "not (cidr <<= '10.0.0.0/8') and ". 90 "not (type = 'wr') and ". 91 "masklen(cidr) <=30"); 92 #" and (custid='6750400' or custid like '%-RES' or custid like '%-BUS')"); 95 93 $sth->execute; 96 94 97 while (my ($cidr,$custid,$type,$city,$description,$ctime,$mtime) = $sth->fetchrow_array()) { 95 $i=0; 96 while (my ($cidr, $custid, $type, $city, $desc, $ctime, $mtime) = $sth->fetchrow_array) { 98 97 99 98 # We get master block info from @masterblocks. … … 110 109 # Updated-By: noc@example.com 111 110 112 # Get the "full" network number - just in case.111 # Get the "full" network number 113 112 my $net = new NetAddr::IP $cidr; 114 113 … … 126 125 or print "File open error: '$!' on '$rwhoisDataPath/$masterfilename'\n"; 127 126 128 if ($data[4] =~ /^\s*$/) { $data[4] = 'Friendly ISP'; } 129 print "$type-type $net for $custid, created $ctime, modified $mtime\n"; 127 # cidr custid type city description notes maskbits 128 129 # Fill in a generic entry for nameless allocations 130 if ($desc =~ /^\s*$/) { $desc = 'Friendly ISP'; } 131 132 # Fix up datestamps. We don't *really* need sub-microsecond resolution on our exports... 133 ($ctime) = ($ctime =~ /^(\d+-\d+-\d+)\s+/); 134 ($mtime) = ($mtime =~ /^(\d+-\d+-\d+)\s+/); 135 130 136 print MASTERFILE "---\nID: NETBLK-ISP.$master\n". 131 137 "Auth-Area: $master\n". … … 133 139 "IP-Network: $net\n". 134 140 "IP-Network-Block: ".$net->range."\n". 135 "Organization: $desc ription\n".141 "Organization: $desc\n". 136 142 # "Tech-Contact: $data[9]\n". 137 143 "Tech-Contact: abuse\@example.com\n". … … 149 155 # print "$data[0]\t| $data[1]\t| $data[2]\t| $data[3]\t| $data[4]\t| ". 150 156 # "$data[5]\t| $data[6]\t| $data[7]\t| $data[8]\n"; 151 157 $i++; 152 158 } # while fetchrow_array() 153 159 154 160 155 161 $dbh->disconnect; 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 };
Note:
See TracChangeset
for help on using the changeset viewer.