source: branches/stable/cgi-bin/extras/db2rwhois.pl@ 198

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

/branches/stable

Merge all changes from /trunk r141-144 and r146

  • Property svn:executable set to *
  • Property svn:keywords set to Date Rev Author
File size: 4.6 KB
RevLine 
[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-02-09 20:53:56 +0000 (Wed, 09 Feb 2005) $
9# SVN revision $Rev: 158 $
10# Last update by $Author: kdeugau $
11###
[158]12# Copyright (C) 2004,2005 - Kris Deugau
[2]13
[15]14use strict;
15use warnings;
[2]16use DBI;
17use NetAddr::IP;
[158]18use MyIPDB;
[2]19
20$ENV{"PATH"} = "/bin;/usr/bin";
21
[15]22my $rwhoisDataPath = "/etc/rwhoisd";
23
[2]24# We'll pull this out of the database instead. Just make sure our
25# master blocks are actually listed.... <g>
26#@masterblocks = (
[15]27# (new NetAddr::IP "209.91.128.0/18"),
28# (new NetAddr::IP "66.186.64.0/19"),
29# (new NetAddr::IP "192.168.99.0/24")
[2]30# );
31
[158]32my ($dbh,$msg) = connectDB_My;
[2]33
[158]34# For WHOIS purposes this may not be very useful. YMMV, we'll see.
35#initIPDBGlobals($dbh);
36
[15]37my @masterblocks;
38
[2]39# Fill in data about our master blocks as allocated from ARIN
40# We open separate files for each of these as appropriate.
41# Note that this ASS-U-MEs that we do not add master IP blocks-
42# there should probably be a separate system for doing that.
[15]43my $sth = $dbh->prepare("select * from masterblocks;");
[2]44$sth->execute;
[15]45my $i=0;
46GETMASTERS: while (my @data = $sth->fetchrow_array()) {
[2]47
[15]48 if ($data[0] =~ /^(192.168.0.0|172.16.0.0|10.0.0.0)/) {
49 next GETMASTERS;
50 }
51 $masterblocks[$i] = new NetAddr::IP $data[0];
[2]52
[15]53print "$masterblocks[$i]\n";
54
55 my $date;
[2]56 chomp ($date = `/bin/date +"%Y%m%d"`);
57
58# Whew! Ugly little varmint.
[15]59 my $masterfilename = "net-".$masterblocks[$i]->addr."-".$masterblocks[$i]->masklen.
[2]60 "/data/network/".$masterblocks[$i]->addr."-".$masterblocks[$i]->masklen.".txt";
61
[15]62# Need check here to create tree for netblock?
[2]63
[15]64 open MASTERFILE,">$rwhoisDataPath/$masterfilename";
65
[2]66 print MASTERFILE "ID: NETBLK-ISP.$masterblocks[$i]\n".
67 "Auth-Area: $masterblocks[$i]\n".
68 "Network-Name: ISP-".$masterblocks[$i]->network."\n".
69 "IP-Network: $masterblocks[$i]\n".
70 "IP-Network-Block: ".$masterblocks[$i]->range."\n".
[15]71 "Organization: Friendly ISP\n".
72 "Tech-Contact: noc\@example.com\n".
[2]73 "Admin-Contact: ISP-ARIN-HANDLE\n".
[15]74 "Abuse-Contact: abuse\@example.com\n".
75 "Created: 20040308\n".
[2]76 "Updated: $date\n".
77 "Updated-By: noc\@example.com\n";
78
79 close MASTERFILE;
80 $i++;
81}
82
83# Now read out the data in the "main" delegation list, and check it
84# with the master blocks. We need to do this to decide which rWHOIS
85# "net-xxx.xxx.xxx.xxx-mask" tree the data belongs in.
86
[15]87# Make sure to remove the private netblocks from this.
88# No use or point in broadcasting our use of them.
89$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'");
[2]90$sth->execute;
91
[15]92while (my @data = $sth->fetchrow_array()) {
[2]93
94# We get master block info from @masterblocks.
95 # ID: NETBLK-ISP.10.0.0.0/8
96 # Auth-Area: 10.0.0.0/8
97 # Network-Name: ISP-10.0.2.144
98 # IP-Network: 10.0.2.144.144/29
99 # IP-Network-Block: 10.0.2.144 - 10.0.2.151
100 # Organization: WidgetCorp
101 # Tech-Contact: bob@widgetcorp.com
102 # Admin-Contact: ISP-ARIN-HANDLE
103 # Created: 20040314
104 # Updated: 20040314
105 # Updated-By: noc@example.com
106
107 # Get the "full" network number
[15]108 my $net = new NetAddr::IP $data[0];
[2]109
110# Assumptions: All data in ipdb is public
111# If not, we need another field to indicate "public/private".
112
[15]113 foreach my $master (@masterblocks) {
[2]114 if ($master->contains($net)) {
115
116# Whew! Ugly little varmint.
[15]117 my $masterfilename = "net-".$master->addr."-".$master->masklen.
[2]118 "/data/network/".$master->addr."-".$master->masklen.".txt";
119
[15]120 open MASTERFILE,">>$rwhoisDataPath/$masterfilename"
121 or print "File open error: '$!' on '$rwhoisDataPath/$masterfilename'\n";
[2]122
[15]123# cidr custid type city description notes maskbits
124
125# Creation date in record to eventually be "correct"; near-term will
126# be master's creation date; immediate is today's date.
127my $date;
[2]128 chomp ($date = `/bin/date +"%Y%m%d"`);
[15]129if ($data[4] =~ /^\s*$/) { $data[4] = 'Friendly ISP'; }
[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".
[15]135 "Organization: $data[4]\n".
[2]136# "Tech-Contact: $data[9]\n".
137 "Tech-Contact: abuse\@example.com\n".
138 "Admin-Contact: ISP-ARIN-HANDLE\n".
[15]139 "Created: $date\n".
[2]140 "Updated: $date\n".
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;
Note: See TracBrowser for help on using the repository browser.