Reputation: 722
Please help how to extract REMOTE_ADDR value using mod_perl.
I have following perl script:
use Apache2::RequestUtil;
use Apache2::RequestRec;
$| = 1;
print "Content-type: text/plain\n\n";
my $r = Apache2::RequestUtil->request;
print $r->as_string();
the result of script:
GET /tmp/recheaders.pl HTTP/1.0
X-Scheme: http
REMOTE_ADDR: 81.204.25.44
Host: dom.net
X-Real-IP: 81.204.25.44
X-Forwarded-for: 81.204.25.44
Connection: close
User-Agent: Opera/9.80 (X11; Linux x86_64) Presto/2.12.388 Version/12.16
Accept: text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/webp, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1
Accept-Language: en-US,en;q=0.9
Accept-Encoding: gzip, deflate
Cookie: SESSION_ID=963bd96302cd70047c9f017640c7cbb8;
Cache-Control: no-cache
HTTP/1.0 (null)
How can I extract only REMOTE_ADDR: 81.204.25.44
? What API method and how should I use?
SOLUTION
I found more elegant solution, to fetch just REMOTE_ADDR using headers_in
:
use Apache2::Request;
my $r = shift;
my $req = Apache2::Request->new($r);
my $remip = $req->headers_in->{REMOTE_ADDR};
print $remip;
Upvotes: 1
Views: 1245
Reputation: 35198
Just use %ENV
print $ENV{REMOTE_ADDR};
Alternatively there is Apache2::Connection->remote_addr()
use Apache2::Connection ();
use Apache2::RequestRec ();
my $c = $r->connection;
# this connection's local and remote socket addresses
my $local_sa = $c->local_addr();
my $remote_sa = $c->remote_addr();
Upvotes: 2