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

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

/trunk

Import rWHOIS export script based on old db

File size: 3.7 KB
Line 
1#!/usr/bin/perl -W -T
2# db2rwhois.pl
3# Pull data from ipdb and mangle it into RWHOIS
4# Initial version 03/26/2004 kdeugau
5
6use DBI;
7use NetAddr::IP;
8
9$ENV{"PATH"} = "/bin;/usr/bin";
10
11# We'll pull this out of the database instead. Just make sure our
12# master blocks are actually listed.... <g>
13#@masterblocks = (
14# (new NetAddr::IP "10.0.0.0/8"),
15# (new NetAddr::IP "172.16.0.0/12"),
16# (new NetAddr::IP "192.168.0.0/16")
17# );
18
19$dbh = DBI->connect("dbi:mysql:ipdb", "root", "")
20 or die $DBI::errstr;
21
22# Fill in data about our master blocks as allocated from ARIN
23# We open separate files for each of these as appropriate.
24# Note that this ASS-U-MEs that we do not add master IP blocks-
25# there should probably be a separate system for doing that.
26$sth = $dbh->prepare("select * from masterblocks;");
27$sth->execute;
28$i=0;
29while (@data = $sth->fetchrow_array()) {
30 # Get the "full" network number+CIDR mask
31 $cidr = $data[0].".".$data[2].$data[1];
32
33 $masterblocks[$i] = new NetAddr::IP $cidr;
34
35 chomp ($date = `/bin/date +"%Y%m%d"`);
36
37# Whew! Ugly little varmint.
38 $masterfilename = "net-".$masterblocks[$i]->addr."-".$masterblocks[$i]->masklen.
39 "/data/network/".$masterblocks[$i]->addr."-".$masterblocks[$i]->masklen.".txt";
40
41 open MASTERFILE,">$masterfilename";
42
43 print MASTERFILE "ID: NETBLK-ISP.$masterblocks[$i]\n".
44 "Auth-Area: $masterblocks[$i]\n".
45 "Network-Name: ISP-".$masterblocks[$i]->network."\n".
46 "IP-Network: $masterblocks[$i]\n".
47 "IP-Network-Block: ".$masterblocks[$i]->range."\n".
48 "Organization: $data[3]\n".
49 "Tech-Contact: $data[9]\n".
50 "Admin-Contact: ISP-ARIN-HANDLE\n".
51 "Created: 20040401000000000\n".
52 "Updated: $date\n".
53 "Updated-By: noc\@example.com\n";
54
55 close MASTERFILE;
56 $i++;
57}
58
59# Now read out the data in the "main" delegation list, and check it
60# with the master blocks. We need to do this to decide which rWHOIS
61# "net-xxx.xxx.xxx.xxx-mask" tree the data belongs in.
62
63#$sth = $dbh->prepare("select * from blocks;");
64$sth = $dbh->prepare("select * from tmpblocks;");
65$sth->execute;
66
67while (@data = $sth->fetchrow_array()) {
68
69# We get master block info from @masterblocks.
70 # ID: NETBLK-ISP.10.0.0.0/8
71 # Auth-Area: 10.0.0.0/8
72 # Network-Name: ISP-10.0.2.144
73 # IP-Network: 10.0.2.144.144/29
74 # IP-Network-Block: 10.0.2.144 - 10.0.2.151
75 # Organization: WidgetCorp
76 # Tech-Contact: bob@widgetcorp.com
77 # Admin-Contact: ISP-ARIN-HANDLE
78 # Created: 20040314
79 # Updated: 20040314
80 # Updated-By: noc@example.com
81
82 # Get the "full" network number
83 $netnum = $data[0].".".$data[2];
84
85 $cidr = $netnum.$data[1];
86
87 $net = new NetAddr::IP $cidr;
88
89# Assumptions: All data in ipdb is public
90# If not, we need another field to indicate "public/private".
91
92 foreach $master (@masterblocks) {
93 if ($master->contains($net)) {
94
95# Whew! Ugly little varmint.
96 $masterfilename = "net-".$master->addr."-".$master->masklen.
97 "/data/network/".$master->addr."-".$master->masklen.".txt";
98
99 open MASTERFILE,">>$masterfilename";
100
101 chomp ($date = `/bin/date +"%Y%m%d"`);
102 print MASTERFILE "---\nID: NETBLK-ISP.$master\n".
103 "Auth-Area: $master\n".
104 "Network-Name: ISP-".$net->network."\n".
105 "IP-Network: $net\n".
106 "IP-Network-Block: ".$net->range."\n".
107 "Organization: $data[5]\n".
108# "Tech-Contact: $data[9]\n".
109 "Tech-Contact: abuse\@example.com\n".
110 "Admin-Contact: ISP-ARIN-HANDLE\n".
111 "Created: <date from db> (or today's date?)\n".
112 "Updated: $date\n".
113 "Updated-By: noc\@example.com\n";
114 }
115 }
116
117
118
119 # print "$data[0]\t| $data[1]\t| $data[2]\t| $data[3]\t| $data[4]\t| ".
120 # "$data[5]\t| $data[6]\t| $data[7]\t| $data[8]\t| $data[9]\n";
121 # print "$data[0]\t| $data[1]\t| $data[2]\t| $data[3]\t| $data[4]\t| ".
122 # "$data[5]\t| $data[6]\t| $data[7]\t| $data[8]\n";
123
124} # while fetchrow_array()
125
126
127$dbh->disconnect;
Note: See TracBrowser for help on using the repository browser.