ipinfo.cgi: Use continent RIR whois server.

Determine the continent for the current processed IP-Address and
send the request to the responsible whois server of the local RIR
instead of sending all requests to ARIN.

Fixes #11267.

Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
This commit is contained in:
Stefan Schantl
2019-12-12 12:08:18 +01:00
parent ec1c52633e
commit 4e033257ef

View File

@@ -41,12 +41,22 @@ my %cgiparams=();
my @lines=();
my $extraquery='';
# Hash which contains the whois servers from
# the responisible RIR of the continent.
my %whois_servers_by_continent = (
"AF" => "whois.afrinic.net",
"AS" => "whois.apnic.net",
"EU" => "whois.ripe.net",
"NA" => "whois.arin.net",
"SA" => "whois.lacnic.net"
);
# Default whois server if no continent could be determined.
my $whois_server = "whois.arin.net";
my $addr = CGI::param("ip") || "";
if (&General::validip($addr)) {
$extraquery='';
@lines=();
my $whoisname = "whois.arin.net";
my $iaddr = inet_aton($addr);
my $hostname = gethostbyaddr($iaddr, AF_INET);
if (!$hostname) { $hostname = $Lang::tr{'lookup failed'}; }
@@ -54,21 +64,31 @@ if (&General::validip($addr)) {
# enumerate GeoIP information for IP address...
my $db_handle = &GeoIP::init();
my $ccode = &GeoIP::lookup_country_code($db_handle, $addr);
# Try to get the continent of the country code.
my $continent = &GeoIP::get_continent_code($db_handle, $ccode);
# Check if a whois server for the continent is known.
if($whois_servers_by_continent{$continent}) {
# Use it.
$whois_server = $whois_servers_by_continent{$continent};
}
my $flag_icon = &GeoIP::get_flag_icon($ccode);
my $sock = new IO::Socket::INET ( PeerAddr => $whoisname, PeerPort => 43, Proto => 'tcp');
my $sock = new IO::Socket::INET ( PeerAddr => $whois_server, PeerPort => 43, Proto => 'tcp');
if ($sock)
{
print $sock "n $addr\n";
print $sock "$addr\n";
while (<$sock>) {
$extraquery = $1 if (/ReferralServer: whois:\/\/(\S+)\s+/);
$extraquery = $1 if (/ReferralServer: whois:\/\/(\S+)\s+/);
push(@lines,$_);
}
close($sock);
if ($extraquery) {
undef (@lines);
$whoisname = $extraquery;
my $sock = new IO::Socket::INET ( PeerAddr => $whoisname, PeerPort => 43, Proto => 'tcp');
$whois_server = $extraquery;
my $sock = new IO::Socket::INET ( PeerAddr => $whois_server, PeerPort => 43, Proto => 'tcp');
if ($sock)
{
print $sock "$addr\n";
@@ -78,16 +98,16 @@ if (&General::validip($addr)) {
}
else
{
@lines = ( "$Lang::tr{'unable to contact'} $whoisname" );
@lines = ( "$Lang::tr{'unable to contact'} $whois_server" );
}
}
}
else
{
@lines = ( "$Lang::tr{'unable to contact'} $whoisname" );
@lines = ( "$Lang::tr{'unable to contact'} $whois_server" );
}
&Header::openbox('100%', 'left', $addr . " <a href='country.cgi#$ccode'><img src='$flag_icon' border='0' align='absmiddle' alt='$ccode' title='$ccode' /></a> (" . $hostname . ') : '.$whoisname);
&Header::openbox('100%', 'left', $addr . " <a href='country.cgi#$ccode'><img src='$flag_icon' border='0' align='absmiddle' alt='$ccode' title='$ccode' /></a> (" . $hostname . ') : '.$whois_server);
print "<pre>\n";
foreach my $line (@lines) {
print &Header::cleanhtml($line,"y");