source: branches/sql-cleanup/cgi-bin/extras/db2rwhois.pl@ 229

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

/trunk

Tweak/update db2rwhois with latest (My)IPDB interface

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