source: trunk/cgi-bin/extras/db2rwhois.pl@ 34

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

Updated db2rwhois.pl for new database format

File size: 4.5 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$
9# SVN revision $Rev$
10# Last update by $Author$
11###
12
13use strict;
14use warnings;
15use DBI;
16use NetAddr::IP;
17use IPDB qw(:ALL);
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 = connectDB;
32
33my @masterblocks;
34
35# Fill in data about our master blocks as allocated from ARIN
36# We open separate files for each of these as appropriate.
37# Note that this ASS-U-MEs that we do not add master IP blocks-
38# there should probably be a separate system for doing that.
39my $sth = $dbh->prepare("select * from masterblocks;");
40$sth->execute;
41my $i=0;
42GETMASTERS: while (my @data = $sth->fetchrow_array()) {
43
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];
48
49print "$masterblocks[$i]\n";
50
51 my $date;
52 chomp ($date = `/bin/date +"%Y%m%d"`);
53
54# Whew! Ugly little varmint.
55 my $masterfilename = "net-".$masterblocks[$i]->addr."-".$masterblocks[$i]->masklen.
56 "/data/network/".$masterblocks[$i]->addr."-".$masterblocks[$i]->masklen.".txt";
57
58# Need check here to create tree for netblock?
59
60 open MASTERFILE,">$rwhoisDataPath/$masterfilename";
61
62 print MASTERFILE "ID: NETBLK-ISP.$masterblocks[$i]\n".
63 "Auth-Area: $masterblocks[$i]\n".
64 "Network-Name: ISP-".$masterblocks[$i]->network."\n".
65 "IP-Network: $masterblocks[$i]\n".
66 "IP-Network-Block: ".$masterblocks[$i]->range."\n".
67 "Organization: Friendly ISP\n".
68 "Tech-Contact: noc\@example.com\n".
69 "Admin-Contact: ISP-ARIN-HANDLE\n".
70 "Abuse-Contact: abuse\@example.com\n".
71 "Created: 20040308\n".
72 "Updated: $date\n".
73 "Updated-By: noc\@example.com\n";
74
75 close MASTERFILE;
76 $i++;
77}
78
79# Now read out the data in the "main" delegation list, and check it
80# with the master blocks. We need to do this to decide which rWHOIS
81# "net-xxx.xxx.xxx.xxx-mask" tree the data belongs in.
82
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'");
86$sth->execute;
87
88while (my @data = $sth->fetchrow_array()) {
89
90# We get master block info from @masterblocks.
91 # ID: NETBLK-ISP.10.0.0.0/8
92 # Auth-Area: 10.0.0.0/8
93 # Network-Name: ISP-10.0.2.144
94 # IP-Network: 10.0.2.144.144/29
95 # IP-Network-Block: 10.0.2.144 - 10.0.2.151
96 # Organization: WidgetCorp
97 # Tech-Contact: bob@widgetcorp.com
98 # Admin-Contact: ISP-ARIN-HANDLE
99 # Created: 20040314
100 # Updated: 20040314
101 # Updated-By: noc@example.com
102
103 # Get the "full" network number
104 my $net = new NetAddr::IP $data[0];
105
106# Assumptions: All data in ipdb is public
107# If not, we need another field to indicate "public/private".
108
109 foreach my $master (@masterblocks) {
110 if ($master->contains($net)) {
111
112# Whew! Ugly little varmint.
113 my $masterfilename = "net-".$master->addr."-".$master->masklen.
114 "/data/network/".$master->addr."-".$master->masklen.".txt";
115
116 open MASTERFILE,">>$rwhoisDataPath/$masterfilename"
117 or print "File open error: '$!' on '$rwhoisDataPath/$masterfilename'\n";
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.
123my $date;
124 chomp ($date = `/bin/date +"%Y%m%d"`);
125if ($data[4] =~ /^\s*$/) { $data[4] = 'Friendly ISP'; }
126 print MASTERFILE "---\nID: NETBLK-ISP.$master\n".
127 "Auth-Area: $master\n".
128 "Network-Name: ISP-".$net->network."\n".
129 "IP-Network: $net\n".
130 "IP-Network-Block: ".$net->range."\n".
131 "Organization: $data[4]\n".
132# "Tech-Contact: $data[9]\n".
133 "Tech-Contact: abuse\@example.com\n".
134 "Admin-Contact: ISP-ARIN-HANDLE\n".
135 "Created: $date\n".
136 "Updated: $date\n".
137 "Updated-By: noc\@example.com\n";
138 }
139 }
140
141
142
143 # print "$data[0]\t| $data[1]\t| $data[2]\t| $data[3]\t| $data[4]\t| ".
144 # "$data[5]\t| $data[6]\t| $data[7]\t| $data[8]\t| $data[9]\n";
145 # print "$data[0]\t| $data[1]\t| $data[2]\t| $data[3]\t| $data[4]\t| ".
146 # "$data[5]\t| $data[6]\t| $data[7]\t| $data[8]\n";
147
148} # while fetchrow_array()
149
150
151$dbh->disconnect;
Note: See TracBrowser for help on using the repository browser.