ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Coro/myhttpd/netgeo.pl
(Generate patch)

Comparing Coro/myhttpd/netgeo.pl (file contents):
Revision 1.9 by root, Sun May 19 21:00:48 2002 UTC vs.
Revision 1.10 by root, Tue Sep 10 04:29:14 2002 UTC

63 my $timeout = 5; 63 my $timeout = 5;
64 64
65 while () { 65 while () {
66 my $fh = new Coro::Socket 66 my $fh = new Coro::Socket
67 PeerAddr => $self->ip, 67 PeerAddr => $self->ip,
68 PeerPort => 'whois', 68 PeerPort => $self->{port} || "whois",
69 Timeout => 30; 69 Timeout => 30;
70 if ($fh) { 70 if ($fh) {
71 print $fh "$query\n"; 71 print $fh "$query\n";
72 $fh->read($whois, 16*1024); # max 16k. whois stored 72 $fh->read($whois, 16*1024); # max 16k. whois stored
73 close $fh; 73 close $fh;
167 $whois; 167 $whois;
168} 168}
169 169
170package Whois::RIPE; 170package Whois::RIPE;
171 171
172use Socket;
172use base Whois; 173use base Whois;
173 174
174sub sanitize { 175sub sanitize {
175 local $_ = $_[1]; 176 local $_ = $_[1];
177
176 s/^%.*\n//gm; 178 s/^%.*\n//gm;
177 s/^\n+//; 179 s/^\n+//;
178 s/\n*$/\n/; 180 s/\n*$/\n/;
181
182 s/^inetnum:\s+/*in: /gm;
183 s/^admin-c:\s+/*ac: /gm;
184 s/^tech-c:\s+/*tc: /gm;
185 s/^owner-c:\s+/*oc: /gm;
186 s/^country:\s+/*cy: /gm;
187 s/^phone:\s+/*ph: /gm;
188 s/^remarks:\s+/*re: /gm;
189 s/^changed:\s+/*ch: /gm;
190 s/^created:\s+/*cr: /gm;
191 s/^address:\s+/*ad: /gm;
192 s/^status:\s+/*st: /gm;
193 s/^inetrev:\s+/*ir: /gm;
194 s/^nserver:\s+/*ns: /gm;
195
179 $_; 196 $_;
180} 197}
181 198
182sub ip_request { 199sub ip_request {
183 my ($self, $ip) = @_; 200 my ($self, $ip) = @_;
184 201
185 my $whois = $self->whois_request("-FSTin $ip"); 202 my $whois = $self->whois_request("$self->{rflags}$ip");
203
204 $whois =~ s{
205 (2[0-5][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])
206 (?:\.
207 (2[0-5][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])
208 (?:\.
209 (2[0-5][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])
210 (?:\.
211 (2[0-5][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])
212 )?
213 )?
214 )?
215 /
216 ([0-9]+)
217 }{
218 my $ip = inet_aton sprintf "%d.%d.%d.%d", $1, $2, $3, $4;
219 my $net = 1 << (31 - $5);
220 my $mask = inet_aton 2 ** 32 - $net;
221
222 my $ip1 = $ip & $mask;
223 my $ip2 = $ip1 | inet_aton $net * 2 - 1;
224 (inet_ntoa $ip1) . " - " . (inet_ntoa $ip2);
225 }gex;
186 226
187 $whois =~ /^\*in: 0\.0\.0\.0 - 255\.255\.255\.255/ 227 $whois =~ /^\*in: 0\.0\.0\.0 - 255\.255\.255\.255/
188 and return; 228 and return;
189 229
190 $whois =~ /^\*ac: XXX0/m # 192.0.0.0 230 $whois =~ /^\*ac: XXX0/m # 192.0.0.0
231 and return;
232
233 $whois =~ /^\*st: (?:ALLOCATED )?UNSPECIFIED/m
191 and return; 234 and return;
192 235
193 $whois =~ /^%ERROR:/m 236 $whois =~ /^%ERROR:/m
194 and return; 237 and return;
195 238
196 #while ($whois =~ s/^\*(?:ac|tc):\s+(\S+)\n//m) { 239 #while ($whois =~ s/^\*(?:ac|tc):\s+(\S+)\n//m) {
197 # $whois .= $self->whois_request("-FSTpn $1"); 240 # $whois .= $self->whois_request("-FSTpn $1");
198 #} 241 #}
199 242
243 #$whois =~ s/^\*(?:pn|nh|mb|ch|so|rz|ny|st|rm):.*\n//mg;
244
245 $whois =~ s/\n+$//;
246
247 $whois;
248}
249
250package Whois::RWHOIS;
251
252use base Whois;
253
254sub sanitize {
255 local $_ = $_[1];
256 s/^%referral\s+/referral:/gm;
257 s/^network://gm;
258 s/^%.*\n//gm;
259 s/^\n+//m;
260 s/\n*$/\n/m;
261
262 s/^(\S+):\s*/\L$1: /gm;
263 s/^ip-network-block:/*in:/gm;
264 s/^country-code:/*cy:/gm;
265 s/^tech-contact;i:/*tc:/gm;
266 s/^updated:/*ch:/gm;
267 s/^street-address:/*ad:/gm;
268 s/^org-name:/*re:/gm;
269 s/^created:/*cr:/gm;
270
271 $_;
272}
273
274sub ip_request {
275 my ($self, $ip) = @_;
276
277 my $whois = $self->whois_request("$ip");
278
279 $whois =~ /^\*in: 0\.0\.0\.0 - 255\.255\.255\.255/
280 and return;
281
282 $whois =~ /^\*ac: XXX0/m # 192.0.0.0
283 and return;
284
285 $whois =~ /^%ERROR:/m
286 and return;
287
288 #while ($whois =~ s/^\*(?:ac|tc):\s+(\S+)\n//m) {
289 # $whois .= $self->whois_request("-FSTpn $1");
290 #}
291
200 $whois =~ s/^\*(?:pn|nh|mb|ch|so|rz|ny|st|rm):.*\n//mg; 292 $whois =~ s/^\*(?:pn|nh|mb|ch|so|rz|ny|st|rm):.*\n//mg;
201 293
202 $whois =~ s/\n+$//; 294 $whois =~ s/\n+$//;
203 295
204 $whois; 296 $whois;
217 inet_ntoa pack "N", $_[0]; 309 inet_ntoa pack "N", $_[0];
218} 310}
219 311
220our %WHOIS; 312our %WHOIS;
221 313
222$WHOIS{ARIN} = new Whois::ARIN ARIN => "whois.arin.net", maxjobs => 12; 314#$WHOIS{ARIN} = new Whois::ARIN ARIN => "whois.arin.net", port => 43, maxjobs => 12;
315$WHOIS{ARIN} = new Whois::RWHOIS ARIN => "rwhois.arin.net", port => 4321, maxjobs => 12;
223$WHOIS{RIPE} = new Whois::RIPE RIPE => "whois.ripe.net", maxjobs => 20; 316$WHOIS{RIPE} = new Whois::RIPE RIPE => "whois.ripe.net", port => 43, rflags => "-FSTin ", maxjobs => 20;
317$WHOIS{APNIC} = new Whois::RIPE APNIC => "whois.apnic.net", port => 43, rflags => "-FSTin ", maxjobs => 20;
224$WHOIS{APNIC} = new Whois::RIPE APNIC => "whois.apnic.net", maxjobs => 20; 318$WHOIS{LACNIC} = new Whois::RIPE LACNIC => "whois.lacnic.net", port => 43, maxjobs => 20;
225 319
226$whoislock = new Coro::SemaphoreSet; 320$whoislock = new Coro::SemaphoreSet;
227 321
228sub ip_request { 322sub ip_request {
229 my $ip = $_[0]; 323 my $ip = $_[0];
242 } 336 }
243 337
244 my ($arin, $ripe, $apnic); 338 my ($arin, $ripe, $apnic);
245 339
246 $whois = $WHOIS{RIPE}->ip_request($ip) 340 $whois = $WHOIS{RIPE}->ip_request($ip)
341 || $WHOIS{LACNIC}->ip_request($ip)
342 || $WHOIS{APNIC} ->ip_request($ip)
247 || $WHOIS{ARIN} ->ip_request($ip) 343 || $WHOIS{ARIN} ->ip_request($ip)
248 || $WHOIS{APNIC} ->ip_request($ip); 344 ;
249 345
250 $whois =~ /^\*in: ([0-9.]+)\s+-\s+([0-9.]+)\s*$/mi 346 $whois =~ /^\*in: ([0-9.]+)\s+-\s+([0-9.]+)\s*$/mi
251 or do { warn "$whois($ip): no addresses found\n", last }; 347 or do { warn "$whois($ip): no addresses found\n", last };
252 348
253 my ($ip0, $ip1) = ($1, $2); 349 my ($ip0, $ip1) = ($1, $2);
267 $iprange->db_sync; 363 $iprange->db_sync;
268 364
269 $whois; 365 $whois;
270} 366}
271 367
368if (0) {
369 #print ip_request "68.52.164.8"; # goof
370 #print "\n\n";
371 #print ip_request "200.202.220.222"; # lacnic
372 #print "\n\n";
373 #print ip_request "62.116.167.250";
374 #print "\n\n";
375 #print ip_request "133.11.128.254"; # jp
376 #print "\n\n";
377 #print ip_request "151.197.52.251";
378 #print "\n\n";
379}
272 380
273 381
382

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines