aboutsummaryrefslogtreecommitdiff
path: root/whoseip/whoseip.pl
diff options
context:
space:
mode:
Diffstat (limited to 'whoseip/whoseip.pl')
-rw-r--r--whoseip/whoseip.pl47
1 files changed, 37 insertions, 10 deletions
diff --git a/whoseip/whoseip.pl b/whoseip/whoseip.pl
index e267a4c..9ca899e 100644
--- a/whoseip/whoseip.pl
+++ b/whoseip/whoseip.pl
@@ -341,6 +341,19 @@ sub nic_or_kr_decode {
}
}
+sub nobistech_decode {
+ my ($input, $ref) = @_;
+
+ if ($input =~ /network:IP-Network:(.+)/) {
+ $ref->{cidr} = $1;
+ $ref->{range} = cidr_to_range($1);
+ $ref->{count} = range2count($ref->{range});
+ } elsif ($input =~ /network:Country-Code:(.+)/) {
+ $ref->{country} = $1;
+ }
+}
+
+
# #######################################################################
# Server table
# #######################################################################
@@ -353,7 +366,8 @@ my %srvtab = (
'whois.twnic.net' => { d => \&twnic_decode },
'whois.nic.ad.jp' => { q => \&nic_ad_jp_fmt, d => \&nic_ad_jp_decode },
'whois.nic.br' => { d => \&lacnic_decode },
- 'whois.nic.or.kr' => { d => \&nic_or_kr_decode },
+ 'whois.nic.or.kr' => { d => \&nic_or_kr_decode },
+ 'rwhois.nobistech.net' => { d => \&nobistech_decode }
);
sub format_query {
@@ -450,10 +464,14 @@ sub serve {
my $srv = findsrv($term);
if (defined($srv) and $srv ne 'UNKNOWN') {
+ my %prev;
while (%res = whois($term, $srv),
and defined($res{referto})) {
+ %prev = %res if $res{status} = 'OK';
$srv = $res{referto};
}
+ %res = %prev
+ if (!defined($res{country}) and defined($prev{country}));
if (!defined($res{country})) {
$res{status} = 'NO';
$res{diag} = 'IP unknown';
@@ -641,6 +659,7 @@ sub docgi {
my $output_format;
my $fastcgi;
+my $single_query;
if (defined($ENV{WHOSEIP_CONF})) {
read_config_file($ENV{WHOSEIP_CONF});
@@ -676,7 +695,8 @@ GetOptions("h" => sub {
},
"fastcgi:s" => \$fastcgi,
"cache-file|c:s" => \$dbfile,
- "no-cache|N" => sub { $dbfile = undef; }
+ "no-cache|N" => sub { $dbfile = undef; },
+ "single-query" => \$single_query
) or exit(EX_USAGE);
if (defined($dbfile)) {
@@ -731,16 +751,19 @@ if ($fastcgi) {
my $term;
my %res;
+ ipdb_locker($dbf, lock => 'shared') if (defined($dbf));
$output_format = $fmtab{unix} unless defined($output_format);
if ($#ARGV == -1) {
unless (-t *STDIN) {
local $/ = CRLF;
$delim = "$CR$LF";
}
- $term = <>;
- chomp $term;
- %res = serve($term);
- format_out($output_format, %res);
+ while (<>) {
+ chomp;
+ %res = serve($_);
+ format_out($output_format, %res);
+ last if $single_query;
+ }
} else {
foreach my $term (@ARGV) {
format_out($output_format, serve($term));
@@ -748,9 +771,7 @@ if ($fastcgi) {
}
}
-if (defined($dbf)) {
- ipdb_close($dbf);
-}
+ipdb_close($dbf) if defined($dbf);
__END__
=head1 NAME
@@ -773,6 +794,7 @@ B<whoiseip>
[B<--formfile=>I<FILE>]
[B<--help>]
[B<--ip-list=>I<FILE>]
+[B<--single-query>]
[B<--usage>]
[I<IPADDR>...]
@@ -949,7 +971,12 @@ I<CIDR> I<SERVER>
Comments are introduced with a B<#> sign. Empty lines are ignored.
Without this option, B<whoseip> uses the built-in list of servers.
-
+
+=item B<--single-query>
+
+This option is valid only in B<inetd mode>. It instructs B<whoseip> to
+terminate after replying to the first query.
+
=back
The following options cause the program to display informative text and

Return to:

Send suggestions and report system problems to the System administrator.