… | |
… | |
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; |
… | |
… | |
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 | return if $whois =~ /^\*de: This network range is not allocated to /; # APINIC e.g. 24.0.0.0 |
|
|
127 | |
121 | |
128 | if ($whois =~ /^To single out one record/m) { |
122 | if ($whois =~ /^To single out one record/m) { |
129 | my $handle; |
123 | my $handle; |
130 | while ($whois =~ /\G\S.*\(([A-Z0-9\-]+)\).*\n/mg) { |
124 | while ($whois =~ /\G\S.*\(([A-Z0-9\-]+)\).*\n/mg) { |
131 | $handle = $1; |
125 | $handle = $1; |
… | |
… | |
231 | }gex; |
225 | }gex; |
232 | |
226 | |
233 | $whois =~ /^\*in: 0\.0\.0\.0 - 255\.255\.255\.255/ |
227 | $whois =~ /^\*in: 0\.0\.0\.0 - 255\.255\.255\.255/ |
234 | and return; |
228 | and return; |
235 | |
229 | |
|
|
230 | $whois =~ /^\*de: This network range is not allocated to /m # APINIC e.g. 24.0.0.0 |
|
|
231 | and return; |
|
|
232 | |
236 | $whois =~ /^\*ac: XXX0/m # 192.0.0.0 |
233 | $whois =~ /^\*ac: XXX0/m # 192.0.0.0 |
237 | and return; |
234 | and return; |
238 | |
235 | |
239 | $whois =~ /^\*st: (?:ALLOCATED )?UNSPECIFIED/m |
236 | $whois =~ /^\*st: (?:ALLOCATED )?UNSPECIFIED/m |
240 | and return; |
237 | and return; |