(file) Return to testgeoipfree.pl CVS log (file) (dir) Up to [RizwankCVS] / geekymedia_web / awstats-6.3 / wwwroot / cgi-bin

 1 rizwank 1.1 #!/usr/bin/perl
 2             #------------------------------------------------------------------------------
 3             # Tool to test your geoipfree setup
 4             # To use it to test your geoip setup instead of geoipfree, comments
 5             # or uncomment appropriated lines
 6             #------------------------------------------------------------------------------
 7             # Exemple of results on Linux Celeron 1.7Ghz
 8             # GeoIPfree:		15s =    485 lookup/s
 9             # GeoIP (PurePerl):	 1s > 10 000 lookup/s
10             # GeoIP (C lib):	 1s > 10 000 lookup/s
11             #------------------------------------------------------------------------------
12             
13             
14             push @INC, ".";
15             push @INC, "./plugins";
16             push @INC, "../wwwroot/cgi-bin/plugins";
17             push @INC, "/home/rizwank/lib/perl/5.6.1";
18             
19             #require "Geo/IPfree.pm";		# For GeoIPfree
20             #require "Geo/IP/PurePerl.pm";	# For GeoIP (PurePerl)
21             require "Geo/IP.pm";			# For GeoIP (C lib)
22 rizwank 1.1 
23             #my $gi = Geo::IPfree->new();												# for GeoIPfree
24             my $gi = Geo::IP->new(Geo::IP::GEOIP_MEMORY_CACHE());						# For GeoIP (C lib)
25             #my $gi = Geo::IP::PurePerl->new(Geo::IP::PurePerl::GEOIP_MEMORY_CACHE());	# For GeoIP (PurePerl)
26             my $gi = Geo::IP->new(Geo::IP::GEOIP_STANDARD());							# For GeoIP (C lib)
27             #my $gi = Geo::IP::PurePerl->new(Geo::IP::PurePerl::GEOIP_STANDARD());		# For GeoIP (PurePerl)
28             
29             
30             $DORESULTTEST=1;
31             $DOSPEEDTEST=1;
32             
33             if ($DORESULTTEST) {
34             	# Do the result test
35             	#-------------------
36             	print "----- Sample test\n";
37             	my %testtodo=(
38                 '212.26.25.24'=>'SA',
39                 '66.108.94.158'=>'US',
40                 '80.8.55.4'=>'FR'
41             	);
42             
43 rizwank 1.1 	foreach my $ip (sort keys %testtodo) {
44             		my ($res,$resname)=();
45             #		($res,$resname)=$gi->LookUp($ip);		# For GeoIPfree
46             		$res=$gi->country_code_by_addr($ip);	# For GeoIP (C lib and PurePerl)
47             		print "Example for $ip: You should get '$testtodo{$ip}' ... and you get '$res".($resname?" $resname":"")."'";
48             		if ($res =~ /$testtodo{$ip}/i) { print " ... Looks good.\n"; }
49             		else { print " ... Looks wrong.\n"; }
50             	}
51             
52             }
53             
54             if ($DOSPEEDTEST) {
55             	# Do the speed test
56             	#------------------
57             	print "----- Speed test\n";
58             	my $timebefore=time();
59             	print "Start at ".localtime($timebefore)." for 10201 lookups\n";
60             	foreach my $j (100..200) {
61             		foreach my $i (100..200) {
62             #			my ($res,$resname)=$gi->LookUp("$j.50.$i.50");				# For GeoIPfree
63             			my ($res)=$gi->country_code_by_addr("$j.50.$i.50");			# For GeoIP (C lib and PurePerl)
64 rizwank 1.1 		}
65             	}
66             	my $timeafter=time();
67             	print "End at ".localtime($timeafter)."\n";
68             	print "Duration: ".($timeafter-$timebefore)." seconds\n";
69             	print "Speed: ".(101*101/(($timeafter-$timebefore)||1))." lookup/s\n";
70             }
71             
72             
73             
74             sleep 3;
75             
76             0;
77             

Rizwan Kassim
Powered by
ViewCVS 0.9.2