#!/usr/bin/perl -w use strict; use lib qw ( ../perllibs ); use CGI; use IP::Country; my $q = new CGI; my $ip2cc = IP::Country->new(); my $cc = lc($ip2cc->inet_atocc($q->remote_host())); if ($cc eq '**'){ $cc = 'us'; } elsif ($cc eq 'uk'){ # naughty, non ISO country code in Perl version $cc = 'gb'; } my $icon = "images/flags/$cc.gif"; if (-e $icon){ print STDOUT $q->header("image/gif"); binmode STDOUT; open (GIF,"$icon") or die ($!); while(read(GIF,my $buf,1024)){ print STDOUT $buf; } close GIF; } else { print $q->header('image/gif','404 Not Found'); } # these flags are from http://sf.net/projects/flags/