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.14 by root, Sat Oct 5 12:42:22 2002 UTC vs.
Revision 1.18 by root, Sat Dec 8 21:01:16 2007 UTC

4 4
5use Socket; 5use Socket;
6use Fcntl; 6use Fcntl;
7 7
8use Coro; 8use Coro;
9use Coro::Event; 9use Coro::EV;
10use Coro::Semaphore; 10use Coro::Semaphore;
11use Coro::SemaphoreSet; 11use Coro::SemaphoreSet;
12use Coro::Socket; 12use Coro::Socket;
13use Coro::Timer; 13use Coro::Timer;
14 14
15use BerkeleyDB; 15use BerkeleyDB;
16
17$Event::DIED = sub {
18 Event::verbose_exception_handler(@_);
19 #Event::unloop_all();
20};
21 16
22tie %netgeo::whois, BerkeleyDB::Btree, 17tie %netgeo::whois, BerkeleyDB::Btree,
23 -Env => $db_env, 18 -Env => $db_env,
24 -Filename => "whois", 19 -Filename => "whois",
25 -Flags => DB_CREATE, 20 -Flags => DB_CREATE,
30 -Flags => DB_CREATE, 25 -Flags => DB_CREATE,
31 or die "unable to create/open iprange table"; 26 or die "unable to create/open iprange table";
32 27
33package Whois; 28package Whois;
34 29
35use Coro::Event; 30use Coro::EV;
36 31
37sub new { 32sub new {
38 my $class = shift; 33 my $class = shift;
39 my $name = shift; 34 my $name = shift;
40 my $ip = shift; 35 my $ip = shift;
120sub ip_request { 115sub ip_request {
121 my ($self, $ip) = @_; 116 my ($self, $ip) = @_;
122 117
123 my $whois = $self->whois_request($ip); 118 my $whois = $self->whois_request($ip);
124 119
125 return () if $whois =~ /^No match/; 120 return if $whois =~ /^No match/;
126 121
127 if ($whois =~ /^To single out one record/m) { 122 if ($whois =~ /^To single out one record/m) {
128 my $handle; 123 my $handle;
129 while ($whois =~ /\G\S.*\(([A-Z0-9\-]+)\).*\n/mg) { 124 while ($whois =~ /\G\S.*\(([A-Z0-9\-]+)\).*\n/mg) {
130 $handle = $1; 125 $handle = $1;
131 #return if $handle =~ /-(RIPE|APNIC)/; # heuristic, bbut bad because ripe might not have better info 126 #return if $handle =~ /-(RIPE|APNIC)/; # heuristic, but bad because ripe might not have better info
132 } 127 }
133 $handle or die "$whois ($ip): unparseable multimatch\n"; 128 $handle or die "$whois ($ip): unparseable multimatch\n";
134 $whois = $self->whois_request("!$handle"); 129 $whois = $self->whois_request("!$handle");
135 } 130 }
136 131
230 }gex; 225 }gex;
231 226
232 $whois =~ /^\*in: 0\.0\.0\.0 - 255\.255\.255\.255/ 227 $whois =~ /^\*in: 0\.0\.0\.0 - 255\.255\.255\.255/
233 and return; 228 and return;
234 229
230 $whois =~ /^\*de: This network range is not allocated to /m # APINIC e.g. 24.0.0.0
231 and return;
232
235 $whois =~ /^\*ac: XXX0/m # 192.0.0.0 233 $whois =~ /^\*ac: XXX0/m # 192.0.0.0
236 and return; 234 and return;
237 235
238 $whois =~ /^\*st: (?:ALLOCATED )?UNSPECIFIED/m 236 $whois =~ /^\*st: (?:ALLOCATED )?UNSPECIFIED/m
239 and return; 237 and return;
316 314
317our %WHOIS; 315our %WHOIS;
318 316
319#$WHOIS{ARIN} = new Whois::ARIN ARIN => "whois.arin.net", port => 43, maxjobs => 12; 317#$WHOIS{ARIN} = new Whois::ARIN ARIN => "whois.arin.net", port => 43, maxjobs => 12;
320$WHOIS{ARIN} = new Whois::RWHOIS ARIN => "rwhois.arin.net", port => 4321, maxjobs => 12; 318$WHOIS{ARIN} = new Whois::RWHOIS ARIN => "rwhois.arin.net", port => 4321, maxjobs => 12;
321$WHOIS{RIPE} = new Whois::RIPE RIPE => "whois.ripe.net", port => 43, rflags => "-FSTin ", maxjobs => 20; 319$WHOIS{RIPE} = new Whois::RIPE RIPE => "whois.ripe.net", port => 43, rflags => "-FTin ", maxjobs => 20;
322$WHOIS{APNIC} = new Whois::RIPE APNIC => "whois.apnic.net", port => 43, rflags => "-FSTin ", maxjobs => 20; 320$WHOIS{APNIC} = new Whois::RIPE APNIC => "whois.apnic.net", port => 43, rflags => "-FTin ", maxjobs => 20;
323$WHOIS{LACNIC} = new Whois::RIPE LACNIC => "whois.lacnic.net", port => 43, maxjobs => 20; 321$WHOIS{LACNIC} = new Whois::RIPE LACNIC => "whois.lacnic.net", port => 43, maxjobs => 20;
324 322
325$whoislock = new Coro::SemaphoreSet; 323$whoislock = new Coro::SemaphoreSet;
326 324
327sub ip_request { 325sub ip_request {
343 my ($arin, $ripe, $apnic); 341 my ($arin, $ripe, $apnic);
344 342
345 $whois = $WHOIS{RIPE}->ip_request($ip) 343 $whois = $WHOIS{RIPE}->ip_request($ip)
346 || $WHOIS{APNIC} ->ip_request($ip) 344 || $WHOIS{APNIC} ->ip_request($ip)
347 || $WHOIS{ARIN} ->ip_request($ip) 345 || $WHOIS{ARIN} ->ip_request($ip)
348 || $WHOIS{LACNIC}->ip_request($ip) 346# || $WHOIS{LACNIC}->ip_request($ip)
349 ; 347 ;
350 348
351 $whois =~ /^\*in: ([0-9.]+)\s+-\s+([0-9.]+)\s*$/mi 349 $whois =~ /^\*in: ([0-9.]+)\s+-\s+([0-9.]+)\s*$/mi
352 or do { warn "$whois($ip): no addresses found\n", last }; 350 or do { warn "$whois($ip): no addresses found\n", last };
353 351
377 #print "\n\n"; 375 #print "\n\n";
378 #print ip_request "62.116.167.250"; 376 #print ip_request "62.116.167.250";
379 #print "\n\n"; 377 #print "\n\n";
380 #print ip_request "133.11.128.254"; # jp 378 #print ip_request "133.11.128.254"; # jp
381 #print "\n\n"; 379 #print "\n\n";
382 #print ip_request "151.197.52.251"; 380 print ip_request "80.131.153.93";
383 #print "\n\n"; 381 print "\n\n";
384} 382}
385 383
3861; 3841;
387 385
388 386

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines