From: Neil Gierman Date: Thu, 30 Aug 2018 03:10:44 +0000 (-0500) Subject: Exclude private IP addresses since GeoIP2::Reader doesn't support them X-Git-Tag: AWSTATS_7_8~22^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a87c2a359b5e80fda2d2ce3c3674b1493aa21cf4;p=thirdparty%2FAWStats.git Exclude private IP addresses since GeoIP2::Reader doesn't support them --- diff --git a/wwwroot/cgi-bin/plugins/geoip2.pm b/wwwroot/cgi-bin/plugins/geoip2.pm index 2bd2d99a..92a71069 100644 --- a/wwwroot/cgi-bin/plugins/geoip2.pm +++ b/wwwroot/cgi-bin/plugins/geoip2.pm @@ -52,6 +52,7 @@ my %TmpDomainLookup; use vars qw/ $reader /; +use Data::Validate::IP 0.25 qw( is_private_ip ); # -----> @@ -199,11 +200,13 @@ sub ShowInfoHost_geoip2 { $address = inet_ntoa(inet_aton($param)); if ($Debug) { debug(" Plugin $PluginName: ShowInfoHost_geoip2 $param resolved to $address",5); } # Now do the same lookup from the IP + # GeoIP2::Reader doesn't support private IP addresses + if (!is_private_ip($address)){ if (!$res){$res=lc($reader->country( ip => $address )->country()->iso_code()) if $reader;} if ($Debug) { debug(" Plugin $PluginName: ShowInfoHost_geoip2 for $param: [$res]",5); } if ($res) { print $DomainsHashIDLib{$res}?$DomainsHashIDLib{$res}:"$Message[0]"; } else { print "$Message[0]"; } - } + }} print ""; } else { diff --git a/wwwroot/cgi-bin/plugins/geoip2_city.pm b/wwwroot/cgi-bin/plugins/geoip2_city.pm index 0591f71a..715f991f 100644 --- a/wwwroot/cgi-bin/plugins/geoip2_city.pm +++ b/wwwroot/cgi-bin/plugins/geoip2_city.pm @@ -55,6 +55,7 @@ $geoip2_city %_city_l $MAXNBOFSECTIONGIR /; +use Data::Validate::IP 0.25 qw( is_private_ip ); # -----> @@ -305,11 +306,13 @@ sub ShowInfoHost_geoip2_city { $address = inet_ntoa(inet_aton($param)); if ($Debug) { debug(" Plugin $PluginName: ShowInfoHost_geoip2_city $param resolved to $address",5); } # Now do the same lookup from the IP + # GeoIP2::Reader doesn't support lookups for Private IPs + if (!is_private_ip($address)){ $record=$geoip2_city->city(ip=>$address) if $geoip2_city; if ($Debug) { debug(" Plugin $PluginName: ShowInfoHost_geoip2_city for $param: [$record]",5); } $country=$record->country()->iso_code() if $record; $city=$record->city()->name() if $record; - } + }} # print ""; # if ($country) { print $DomainsHashIDLib{$country}?$DomainsHashIDLib{$country}:"$Message[0]"; } # else { print "$Message[0]"; }