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

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

Fix missing svn:keywords revision info in scripts

  • Property svn:executable set to *
  • Property svn:keywords set to Date Rev Author
File size: 4.5 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: 2004-10-26 17:03:16 +0000 (Tue, 26 Oct 2004) $
9# SVN revision $Rev: 26 $
10# Last update by $Author: kdeugau $
11###
[2]12
[15]13use strict;
14use warnings;
[2]15use DBI;
16use NetAddr::IP;
[15]17use IPDB qw(:ALL);
[2]18
19$ENV{"PATH"} = "/bin;/usr/bin";
20
[15]21my $rwhoisDataPath = "/etc/rwhoisd";
22
[2]23# We'll pull this out of the database instead. Just make sure our
24# master blocks are actually listed.... <g>
25#@masterblocks = (
[15]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")
[2]29# );
30
[15]31my $dbh = connectDB;
[2]32
[15]33my @masterblocks;
34
[2]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.
[15]39my $sth = $dbh->prepare("select * from masterblocks;");
[2]40$sth->execute;
[15]41my $i=0;
42GETMASTERS: while (my @data = $sth->fetchrow_array()) {
[2]43
[15]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];
[2]48
[15]49print "$masterblocks[$i]\n";
50
51 my $date;
[2]52 chomp ($date = `/bin/date +"%Y%m%d"`);
53
54# Whew! Ugly little varmint.
[15]55 my $masterfilename = "net-".$masterblocks[$i]->addr."-".$masterblocks[$i]->masklen.
[2]56 "/data/network/".$masterblocks[$i]->addr."-".$masterblocks[$i]->masklen.".txt";
57
[15]58# Need check here to create tree for netblock?
[2]59
[15]60 open MASTERFILE,">$rwhoisDataPath/$masterfilename";
61
[2]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".
[15]67 "Organization: Friendly ISP\n".
68 "Tech-Contact: noc\@example.com\n".
[2]69 "Admin-Contact: ISP-ARIN-HANDLE\n".
[15]70 "Abuse-Contact: abuse\@example.com\n".
71 "Created: 20040308\n".
[2]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
[15]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'");
[2]86$sth->execute;
87
[15]88while (my @data = $sth->fetchrow_array()) {
[2]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
[15]104 my $net = new NetAddr::IP $data[0];
[2]105
106# Assumptions: All data in ipdb is public
107# If not, we need another field to indicate "public/private".
108
[15]109 foreach my $master (@masterblocks) {
[2]110 if ($master->contains($net)) {
111
112# Whew! Ugly little varmint.
[15]113 my $masterfilename = "net-".$master->addr."-".$master->masklen.
[2]114 "/data/network/".$master->addr."-".$master->masklen.".txt";
115
[15]116 open MASTERFILE,">>$rwhoisDataPath/$masterfilename"
117 or print "File open error: '$!' on '$rwhoisDataPath/$masterfilename'\n";
[2]118
[15]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;
[2]124 chomp ($date = `/bin/date +"%Y%m%d"`);
[15]125if ($data[4] =~ /^\s*$/) { $data[4] = 'Friendly ISP'; }
[2]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".
[15]131 "Organization: $data[4]\n".
[2]132# "Tech-Contact: $data[9]\n".
133 "Tech-Contact: abuse\@example.com\n".
134 "Admin-Contact: ISP-ARIN-HANDLE\n".
[15]135 "Created: $date\n".
[2]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.