There's more than one way to do things | |
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?? |
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.
In Section
Seekers of Perl Wisdom
|
|