No, if you're running in a CGI environment then per the spec then REMOTE_ADDR must be set to the address of the client sending the request. Now due to proxies and other network vagaries that might not be the IP address the client machine uses on its local network (which is another question / issue; if you think it should be the "real" IP the client knows itself as you're mistaken about what CGI provides), but it will be what the serving machine sees the connection as having come from.

And yes the environment variables are what CGI will use to set its members (because that's how CGI works). Again, it's correct per the spec and presuming a functioning webserver implementing the CGI interface they'll be there.

Edit: Of course if you're not running as a CGI script then that's a different horse of another color. But the limitation remains; if you're running under (say) mod_perl then that's going to be populating from the address stashed in the request structure (same that mod_cgi would use to fill out those environment variables) but (again) that address is going to be what the server sees the client connection as originating from. There's no magic that's going to make that show the "real" local network address of the client if there's proxies or NAT or avian carriers or what have you in the mix.

The cake is a lie.
The cake is a lie.
The cake is a lie.


In reply to Re^2: Can my perl scripts get the IP address that called the script? by Fletch
in thread Can my perl scripts get the IP address that called the script? by bartender1382

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.