GeoIP Coutnry for resolved IPs?

Developers
alvin
2005-03-22
2012-10-11
  • alvin
    alvin
    2005-03-22

    I hate to repost this, but perhaps this problem belongs in this forum?

    I have installed awstats 6.4 and it's great! The only issue I have noticed is the GeoIP Country field in the Hosts table. I only see the country names for IP addresses and not the resolved addresses. My webserver logs contain resolved and unresolved addresses.

    I am using:

    geoip GEOIP_STANDARD (default in the config file)

    Any ideas was what is causing this? Thanks.

     
    • GeoIP should work for both resolved and unresolved ip adress.

      Try the following script (you should get 4 "Looks good")

      !/usr/bin/perl

      ------------------------------------------------------------------------------

      Tool to test your geoip setup

      ------------------------------------------------------------------------------

      Exemple of results

      ------------------------------------------------------------------------------

      push @INC, ".";
      push @INC, "./plugins";
      push @INC, "../wwwroot/cgi-bin/plugins";

      use Test;

      require "Geo/IPfree.pm"; # For GeoIPfree

      require "Geo/IP/PurePerl.pm"; # For GeoIP (PurePerl)

      use Geo::IP; # For GeoIP (C lib)

      my $gi = Geo::IP->open("c:\Program files\GeoIP\GeoIPRegion-515.dat", Geo::IP::GEOIP_MEMORY_CACHE());

      my $gi = Geo::IP->open("/usr/local/share/GeoIP/GeoIP.dat", Geo::IP::GEOIP_STANDARD());

      my $gi = Geo::IP->new(Geo::IP::GEOIP_STANDARD());

      my $gi = Geo::IP::PurePerl->new(Geo::IP::PurePerl::GEOIP_MEMORY_CACHE()); # For GeoIP (PurePerl)

      my $gi = Geo::IP->new(Geo::IP::GEOIP_STANDARD()); # For GeoIP (C lib)

      my $gi = Geo::IP::PurePerl->new(Geo::IP::PurePerl::GEOIP_STANDARD()); # For GeoIP (PurePerl)

      $DORESULTTEST=1;
      $DOSPEEDTEST=1;

      if ($DORESULTTEST) {
      # Do the result test
      #-------------------
      print "----- Sample test\n";
      my %testtodo=(
      '212.26.25.24'=>'SA',
      '66.108.94.158'=>'US',
      '80.8.55.4'=>'FR',
      'ca-sqy-1-40.w80-8.abo.wanadoo.fr'=>'FR'
      );

      foreach my $ip (sort keys %testtodo) {
          my ($res1,$res2) = ($gi->country_code_by_name($ip),$gi->country_code_by_addr($ip));  # For GeoIP (C lib)
          print "Example for $ip: You should get '$testtodo{$ip}' ... and you get '$res1', '$res2'";
          if ($res1 =~ /$testtodo{$ip}/i || $res2 =~ /$testtodo{$ip}/i) { print " ... Looks good.\n"; }
          else { print " ... Looks wrong.\n"; }
      }
      

      }

      if ($DOSPEEDTEST) {
      # Do the speed test
      #------------------
      print "----- Speed test\n";
      my $timebefore=time();
      print "Start at ".localtime($timebefore)." for 40401 lookups\n";
      foreach my $j (50..250) {
      foreach my $i (50..250) {
      my ($res)=$gi->country_code_by_addr("$j.50.$i.50"); # For GeoIP (C lib)
      }
      }
      my $timeafter=time();
      print "End at ".localtime($timeafter)."\n";
      print "Duration: ".($timeafter-$timebefore)." seconds\n";
      print "Speed: ".(201*201/(($timeafter-$timebefore)||1))." lookup/s\n";
      }

      sleep 3;

      0;

       
    • Also a bug in geoip plugin has just bee, found and fixed in 6.5 beta.

       
    • Rick Morris
      Rick Morris
      2005-05-06

      Something else with GeoIP:

      $TmpDomainLookup keeps track of previously resolved entries, but doesn't get set if the lookup fails. This causes failed lookups to get retried for every line in the stats source. Since gethostbyname(), which GeoIP ultimately uses, will query every name server in resolv.conf, and each must timeout, this can slow stats down horribly.

      I've used this diff (vs. 1.14) successfully to fix this
      diff -c awstats-6.3/wwwroot/cgi-bin/plugins/geoip.pm awstats-6.3.orig/wwwroot/cgi-bin/plugins/geoip.pm
      awstats-6.3/wwwroot/cgi-bin/plugins/geoip.pm 2005-02-07 09:19:25.000000000 -0800
      --- awstats-6.3.orig/wwwroot/cgi-bin/plugins/geoip.pm 2005-01-22 08:39:53.000000000 -0800
      ***
      85,91 *
      my $res=$TmpDomainLookup{$param}||'';
      if (! $res) {
      $res=lc($gi->country_code_by_name($param));
      ! $TmpDomainLookup{$param}=$res || 'unknown';
      if ($Debug) { debug(" Plugin geoip: GetCountryCodeByName for $param: [$res]",5); }
      }
      elsif ($Debug) { debug(" Plugin geoip: GetCountryCodeByName for $param: Already resolved to $res",5); }
      --- 85,91 ----
      my $res=$TmpDomainLookup{$param}||'';
      if (! $res) {
      $res=lc($gi->country_code_by_name($param));
      ! $TmpDomainLookup{$param}=$res;
      if ($Debug) { debug(" Plugin geoip: GetCountryCodeByName for $param: [$res]",5); }
      }
      elsif ($Debug) { debug(" Plugin geoip: GetCountryCodeByName for $param: Already resolved to $res",5); }
      ***
      104,110 ****
      my $res=$TmpDomainLookup{$param}||'';
      if (! $res) {
      $res=lc($gi->country_code_by_addr($param));
      ! $TmpDomainLookup{$param}=$res || 'unknown';
      if ($Debug) { debug(" Plugin geoip: GetCountryCodeByAddr for $param: $res",5); }
      }
      elsif ($Debug) { debug(" Plugin geoip: GetCountryCodeByAddr for $param: Already resolved to $res",5); }
      --- 104,110 ----
      my $res=$TmpDomainLookup{$param}||'';
      if (! $res) {
      $res=lc($gi->country_code_by_addr($param));
      ! $TmpDomainLookup{$param}=$res;
      if ($Debug) { debug(" Plugin geoip: GetCountryCodeByAddr for $param: $res",5); }
      }
      elsif ($Debug) { debug(" Plugin geoip: GetCountryCodeByAddr for $param: Already resolved to $res",5); }