OK... let me get out my Acme® brand flashlight here. When I run a script that basically just dumps all the elements of the %ENV hash on my server here is a sanitized version of what I get back:

DOCUMENT_ROOT /path/to/doc/root/www.mydomain.com GATEWAY_INTERFACE CGI/1.1 HTTP_ACCEPT text/xml,application/xml,application/xhtml+xml,text/ht +ml;q=0.9,text/plain;q=0.8,video/x-mng,image/png,image/jpeg,image/gif; +q=0.2,*/*;q=0.1 HTTP_ACCEPT_CHARSET ISO-8859-1,utf-8;q=0.7,*;q=0.7 HTTP_ACCEPT_ENCODING gzip,deflate HTTP_ACCEPT_LANGUAGE en-us,en;q=0.5 HTTP_CONNECTION keep-alive HTTP_HOST www.mydomain.com HTTP_KEEP_ALIVE 300 HTTP_USER_AGENT Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4.2) +Gecko/20040301 PATH /usr/local/bin:/usr/bin:/bin QUERY_STRING REMOTE_ADDR 4.3.2.1 REMOTE_PORT 33161 REQUEST_METHOD GET REQUEST_URI /cgi-bin/fooCheck.pl SCRIPT_FILENAME /usr/web/www.berghold.net/cgi-bin/fooCheck.pl SCRIPT_NAME /cgi-bin/fooCheck.pl SERVER_ADDR 1.2.3.4 SERVER_ADMIN webmaster@mydomain.com SERVER_NAME www.mydomain.com SERVER_PORT 80 SERVER_PROTOCOL HTTP/1.1 SERVER_SOFTWARE Apache/1.3.29 (Unix) AuthMySQL/2.20 PHP/4.3.4 mod_ +perl/1.24 mod_ssl/2.8.16 OpenSSL/0.9.7c UNIQUE_ID QHMCUdiLkw8AAAVExU8

A quick glance reveals a value for REMOTE_ADDR which when I check the NAT'ed address for my client what I see there matches what I know my NAT'ed IP address to be.

AHA!

There-in lies one of the problems a coder has in trying to capture IP addresses of browsers. If the browser client is behind a NAT'ing firewall then all you are going to collect is the NAT address. Most network admins that do NAT use a single address for multiple desktop clients and individual IP addresses only for machines they want visible to the outside world. My home network is one of those.

If you are interested here is a subset of the code that generated that output:

use CGI qw(:all); print header,start_html; env_test(); print end_html; exit(0); sub env_test { print h2('Base Account (shell) Environment'); print table( map { Tr(td($_),td($ENV{$_})) } sort keys %ENV ); print p(b('CGI Runs As:'),`id`); print p(b('Current working directory is:'),`pwd`); print p("I was invoked as: ",$0); if ($ENV{HOME}) { if (-d $ENV{HOME} . '/cgi-bin') { print p('Found the cgi-bin directory in ', $ENV{HOME} . "/cgi-bi +n"); } else { print p("I have no clue where the cgi-bin is physically"); } } else { print p(b('OH DRAT!'),'The $HOME variable is not being set!'); } }


In reply to Re: Using CGI (Perl) and javascript at the same time by blue_cowdawg
in thread Using CGI (Perl) and javascript at the same time by krt6

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.