[Melbourne-pm] finding the ip address of the web client

Tim Hogard thogard at abnormal.com
Mon Feb 9 16:49:55 PST 2009


> 
> %ENV{'REMOTE_ADDR '} should contain the IP address of the client. Try
> this:
> =20
> -----
> =20
> #!/usr/bin/perl
> print "content-type:text/html\n\n<html><body>\n";
> foreach(keys(%ENV))
> {
>         print "$_ =3D $ENV{$_}<BR>\n";
> }
> print "</body></html>\n";
> 

If the rmote is behind a an honest proxy it may give you this to:
 HTTP_X_FORWARDED_FOR

Also
> %ENV{'REMOTE_ADDR'} should contain the IP address of the client. Try
                   ^ no space...


Other comments...
reverse DNS is often very slow and may timeout.
maxmind has a free database and perl module that has IP->country code
mappings.
You can't trust anyones reverse IP.
You also need to make sure your CGI program framework can't over write the
REMOTE_ADDR.

-tim


More information about the Melbourne-pm mailing list