Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^2: Can my perl scripts get the IP address that called the script?

by Fletch (Bishop)
on Apr 13, 2022 at 15:03 UTC ( [id://11142959]=note: print w/replies, xml ) Need Help??


in reply to Re: Can my perl scripts get the IP address that called the script?
in thread Can my perl scripts get the IP address that called the script?

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.

  • Comment on Re^2: Can my perl scripts get the IP address that called the script?
  • Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11142959]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (1)
As of 2024-04-25 00:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found