source: branches/new-custids/cgi-bin/extras/db2rwhois.pl@ 241

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

/trunk

Update copyright statements

  • 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-02-01 22:02:39 +0000 (Tue, 01 Feb 2005) $
9# SVN revision $Rev: 146 $
10# Last update by $Author: kdeugau $
11###
12# Copyright (C) 2004,2005 - Kris Deugau
13
14use strict;
15use warnings;
16use DBI;
17use NetAddr::IP;
18use MyIPDB;
19
20$ENV{"PATH"} = "/bin;/usr/bin";
21
22my $rwhoisDataPath = "/etc/rwhoisd";
23
24# We'll pull this out of the database instead. Just make sure our
25# master blocks are actually listed.... <g>
26#@masterblocks = (
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")
30# );
31
32my ($dbh,$msg) = connectDB_My;
33
34# For WHOIS purposes this may not be very useful. YMMV, we'll see.
35#initIPDBGlobals($dbh);
36
37my @masterblocks;
38
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.
43my $sth = $dbh->prepare("select * from masterblocks;");
44$sth->execute;
45my $i=0;
46GETMASTERS: while (my @data = $sth->fetchrow_array()) {
47
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];
52
53print "$masterblocks[$i]\n";
54
55 my $date;
56 chomp ($date = `/bin/date +"%Y%m%d"`);
57
58# Whew! Ugly little varmint.
59 my $masterfilename = "net-".$masterblocks[$i]->addr."-".$masterblocks[$i]->masklen.
60 "/data/network/".$masterblocks[$i]->addr."-".$masterblocks[$i]->masklen.".txt";
61
62# Need check here to create tree for netblock?
63
64 open MASTERFILE,">$rwhoisDataPath/$masterfilename";
65
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".
71 "Organization: Friendly ISP\n".
72 "Tech-Contact: noc\@example.com\n".
73 "Admin-Contact: ISP-ARIN-HANDLE\n".
74 "Abuse-Contact: abuse\@example.com\n".
75 "Created: 20040308\n".
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
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'");
90$sth->execute;
91
92while (my @data = $sth->fetchrow_array()) {
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
108 my $net = new NetAddr::IP $data[0];
109
110# Assumptions: All data in ipdb is public
111# If not, we need another field to indicate "public/private".
112
113 foreach my $master (@masterblocks) {
114 if ($master->contains($net)) {
115
116# Whew! Ugly little varmint.
117 my $masterfilename = "net-".$master->addr."-".$master->masklen.
118 "/data/network/".$master->addr."-".$master->masklen.".txt";
119
120 open MASTERFILE,">>$rwhoisDataPath/$masterfilename"
121 or print "File open error: '$!' on '$rwhoisDataPath/$masterfilename'\n";
122
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;
128 chomp ($date = `/bin/date +"%Y%m%d"`);
129if ($data[4] =~ /^\s*$/) { $data[4] = 'Friendly ISP'; }
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".
135 "Organization: $data[4]\n".
136# "Tech-Contact: $data[9]\n".
137 "Tech-Contact: abuse\@example.com\n".
138 "Admin-Contact: ISP-ARIN-HANDLE\n".
139 "Created: $date\n".
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.