if (! $param) { return ''; }
my $res= TmpLookup_geoip2($param);
if (! $res) {
- if ($Debug) { debug(" Plugin $PluginName: GetCountryCodeByAddr for $param",5); }
+ if ($Debug) { debug(" Plugin $PluginName: GetCountryCodeByAddr_geoip2 for $param",5); }
$res=lc($reader->country( ip => $param )->country()->iso_code()) || 'unknown';
$TmpDomainLookup{$param}=$res;
- if ($Debug) { debug(" Plugin $PluginName: GetCountryCodeByAddr for $param: [$res]",5); }
+ if ($Debug) { debug(" Plugin $PluginName: GetCountryCodeByAddr_geoip2 for $param: [$res]",5); }
}
- elsif ($Debug) { debug(" Plugin $PluginName: GetCountryCodeByAddr for $param: Already resolved to [$res]",5); }
+ elsif ($Debug) { debug(" Plugin $PluginName: GetCountryCodeByAddr_geoip2 for $param: Already resolved to [$res]",5); }
# ----->
return $res;
}
if (! $res) {
# First resolve the name to an IP
$address = inet_ntoa(inet_aton($param));
- if ($Debug) { debug(" Plugin $PluginName: GetCountryCodeByName $param resolved to $address",5); }
+ if ($Debug) { debug(" Plugin $PluginName: GetCountryCodeByName_geoip2 $param resolved to $address",5); }
# Now do the same lookup from the IP
$res=lc($reader->country( ip => $address )->country()->iso_code()) || 'unknown';
$TmpDomainLookup{$param}=$res;
- if ($Debug) { debug(" Plugin $PluginName: GetCountryCodeByName for $param: [$res]",5); }
+ if ($Debug) { debug(" Plugin $PluginName: GetCountryCodeByName_geoip2 for $param: [$res]",5); }
}
- elsif ($Debug) { debug(" Plugin $PluginName: GetCountryCodeByName for $param: Already resolved to [$res]",5); }
+ elsif ($Debug) { debug(" Plugin $PluginName: GetCountryCodeByName_geoip2 for $param: Already resolved to [$res]",5); }
# ----->
return $res;
}
}
print "<td>";
if ($key && $ip==4) {
- if ($Debug) { debug(" Plugin $PluginName: GetCountryByIp for $param key=$key ip=$ip",5); }
+ if ($Debug) { debug(" Plugin $PluginName: ShowInfoHost_geoip2 for $param key=$key ip=$ip",5); }
my $res = TmpLookup_geoip2($param);
if (!$res){$res=lc($reader->country( ip => $param )->country()->iso_code()) if $reader;}
- if ($Debug) { debug(" Plugin $PluginName: GetCountryByIp for $param: [$res]",5); }
+ if ($Debug) { debug(" Plugin $PluginName: ShowInfoHost_geoip2 for $param: [$res]",5); }
if ($res) { print $DomainsHashIDLib{$res}?$DomainsHashIDLib{$res}:"<span style=\"color: #$color_other\">$Message[0]</span>"; }
else { print "<span style=\"color: #$color_other\">$Message[0]</span>"; }
}
if ($key && $ip==6) { # GeoIP2 supports both IPv4 and IPv6
- if ($Debug) { debug(" Plugin $PluginName: GetCountryByIp for $param key=$key ip=$ip",5); }
+ if ($Debug) { debug(" Plugin $PluginName: ShowInfoHost_geoip2 for $param key=$key ip=$ip",5); }
my $res = TmpLookup_geoip2($param);
if (!$res){$res=lc($reader->country( ip => $param )->country()->iso_code()) if $reader;}
- if ($Debug) { debug(" Plugin $PluginName: GetCountryByIp for $param: [$res]",5); }
+ if ($Debug) { debug(" Plugin $PluginName: ShowInfoHost_geoip2 for $param: [$res]",5); }
if ($res) { print $DomainsHashIDLib{$res}?$DomainsHashIDLib{$res}:"<span style=\"color: #$color_other\">$Message[0]</span>"; }
else { print "<span style=\"color: #$color_other\">$Message[0]</span>"; }
}
if (! $key) {
- if ($Debug) { debug(" Plugin $PluginName: GetCountryByIp for $param key=$key ip=$ip",5); }
+ if ($Debug) { debug(" Plugin $PluginName: ShowInfoHost_geoip2 for $param key=$key ip=$ip",5); }
my $res = TmpLookup_geoip2($param);
# First resolve the name to an IP
$address = inet_ntoa(inet_aton($param));
- if ($Debug) { debug(" Plugin $PluginName: GetCountryCodeByName $param resolved to $address",5); }
+ if ($Debug) { debug(" Plugin $PluginName: ShowInfoHost_geoip2 $param resolved to $address",5); }
# Now do the same lookup from the IP
if (!$res){$res=lc($reader->country( ip => $address )->country()->iso_code()) if $reader;}
- if ($Debug) { debug(" Plugin $PluginName: GetCountryByHostname for $param: [$res]",5); }
+ if ($Debug) { debug(" Plugin $PluginName: ShowInfoHost_geoip2 for $param: [$res]",5); }
if ($res) { print $DomainsHashIDLib{$res}?$DomainsHashIDLib{$res}:"<span style=\"color: #$color_other\">$Message[0]</span>"; }
else { print "<span style=\"color: #$color_other\">$Message[0]</span>"; }
}
return 0;
}
-
-#-----------------------------------------------------------------------------
-# PLUGIN FUNCTION: GetCountryCodeByAddr_pluginname
-# UNIQUE: YES (Only one plugin using this function can be loaded)
-# GetCountryCodeByAddr is called to translate an ip into a country code in lower case.
-#-----------------------------------------------------------------------------
-# Rem: not used
-sub GetCountryCodeByAddr_geoip2_city {
- my $param="$_[0]";
- # <-----
- my $res = TmpLookup_geoip2_city($param);
- if (! $res) {
- my $record=();
- $record=$geoip2_city->city(ip=>$param) if $geoip2_city;
- my $country;
- $country=$record->country()->iso_code() if $record;
- $res=lc($country) || 'unknown';
- $TmpDomainLookup{$param}=$res;
- if ($Debug) { debug(" Plugin $PluginName: GetCountryCodeByAddr for $param: [$res]",5); }
- }
- elsif ($Debug) { debug(" Plugin $PluginName: GetCountryCodeByAddr for $param: Already resolved to [$res]",5); }
- # ----->
- return $res;
-}
-
-
-#-----------------------------------------------------------------------------
-# PLUGIN FUNCTION: GetCountryCodeByName_pluginname
-# UNIQUE: YES (Only one plugin using this function can be loaded)
-# GetCountryCodeByName is called to translate a host name into a country code in lower case.
-#-----------------------------------------------------------------------------
-# Rem: not used
-sub GetCountryCodeByName_geoip2_city {
- my $param="$_[0]";
- # <-----
- my $res = TmpLookup_geoip2_city($param);
- if ($type eq 'geoippureperl') {
- if (! $res) {
- my @record = ();
- @record=$geoip2_city->get_city_record($param) if $geoip2_city;
- my $country;
- $country=$record[0] if @record;
- $res=lc($country) || 'unknown';
- $TmpDomainLookup{$param}=$res;
- if ($Debug) { debug(" Plugin $PluginName: GetCountryCodeByName for $param: [$res]",5); }
- }
- elsif ($Debug) { debug(" Plugin $PluginName: GetCountryCodeByName for $param: Already resolved to [$res]",5); }
- }
- else
- {
- if (! $res) {
- my $record=();
- $record=$geoip2_city->record_by_name($param) if $geoip2_city;
- my $country;
- $country=$record->country if $record;
- $res=lc($country) || 'unknown';
- $TmpDomainLookup{$param}=$res;
- if ($Debug) { debug(" Plugin $PluginName: GetCountryCodeByName for $param: [$res]",5); }
- }
- elsif ($Debug) { debug(" Plugin $PluginName: GetCountryCodeByName for $param: Already resolved to [$res]",5); }
- }
- # ----->
- return $res;
-}
-
-
#-----------------------------------------------------------------------------
# PLUGIN FUNCTION: ShowInfoHost_pluginname
# UNIQUE: NO (Several plugins using this function can be loaded)
else
{
my $record=();
+ if ($Debug) { debug(" Plugin $PluginName: ShowInfoHost_geoip2_city for $param",5); }
$record=$geoip2_city->city(ip=>$param) if $geoip2_city;
- if ($Debug) { debug(" Plugin $PluginName: GetCityByIp for $param: [".$record->city()->name()."]",5); }
+ if ($Debug) { debug(" Plugin $PluginName: ShowInfoHost_geoip2_city for $param: [".$record->city()->name()."]",5); }
$country=$record->country()->iso_code() if $record;
$city=$record->city()->name() if $record;
}
else
{
my $record=();
- $record=$geoip2_city->city(ip=>$param) if $geoip2_city;
- if ($Debug) { debug(" Plugin $PluginName: GetCityByHostname for $param: [$record]",5); }
+ # First resolve the name to an IP
+ $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
+ $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;
}
$record->region = $rec[0];
$record->country_code = $rec[3];
}else{
+ if ($Debug) { debug(" Plugin $PluginName: SectionProcessIp_geoip2_city for $param",5); }
$record=$geoip2_city->city(ip=>$param) if $geoip2_city;
}
if ($Debug) { debug(" Plugin $PluginName: GetCityByIp for $param: [".$record->city()->name()."]",5); }
$record->region = $rec[3];
$record->country_code = $rec[0];
}else{
- $record=$geoip2_city->city(ip=>$param) if $geoip2_city;
+ # First resolve the name to an IP
+ $address = inet_ntoa(inet_aton($param));
+ if ($Debug) { debug(" Plugin $PluginName: SectionProcessHostname_geoip2_city $param resolved to $address",5); }
+ # Now do the same lookup from the IP
+ $record=$geoip2_city->city(ip=>$address) if $geoip2_city;
}
if ($Debug) { debug(" Plugin $PluginName: GetCityByName for $param: [$record]",5); }
if ($record) {