… | |
… | |
4 | |
4 | |
5 | use Socket; |
5 | use Socket; |
6 | use Fcntl; |
6 | use Fcntl; |
7 | |
7 | |
8 | use Coro; |
8 | use Coro; |
9 | use Coro::Event; |
9 | use Coro::EV; |
10 | use Coro::Semaphore; |
10 | use Coro::Semaphore; |
11 | use Coro::SemaphoreSet; |
11 | use Coro::SemaphoreSet; |
12 | use Coro::Socket; |
12 | use Coro::Socket; |
13 | use Coro::Timer; |
13 | use Coro::Timer; |
14 | |
14 | |
15 | use BerkeleyDB; |
15 | use BerkeleyDB; |
16 | |
|
|
17 | $Event::DIED = sub { |
|
|
18 | Event::verbose_exception_handler(@_); |
|
|
19 | #Event::unloop_all(); |
|
|
20 | }; |
|
|
21 | |
16 | |
22 | tie %netgeo::whois, BerkeleyDB::Btree, |
17 | tie %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 | |
33 | package Whois; |
28 | package Whois; |
34 | |
29 | |
35 | use Coro::Event; |
30 | use Coro::EV; |
36 | |
31 | |
37 | sub new { |
32 | sub 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; |
… | |
… | |
120 | sub ip_request { |
115 | sub 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 | |
317 | our %WHOIS; |
315 | our %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 | |
327 | sub ip_request { |
325 | sub 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 | |
386 | 1; |
384 | 1; |
387 | |
385 | |
388 | |
386 | |