r1n0 has asked for the wisdom of the Perl Monks concerning the following question:

I appreciate all the feedback I have received thus far while learning HTTP::Proxy. It has been extremely helpful.

. Can someone tell me how to identify the IP address of the client system while using HTTP::Proxy?

. Here is a little snippet of code and I mainly want to know if I can identify the client with one of the items in the Filter area:

#!/usr/bin/perl use HTTP::Proxy; use HTTP::Proxy::HeaderFilter::simple; use Digest::SHA1 qw(sha1_hex); my $proxy = HTTP::Proxy->new( host => '192.168.0.1', port => 8080 ); my $filter = HTTP::Proxy::HeaderFilter::simple->new( sub { my ($self, $headers, $request) = @_; my $uri = $request->uri(); my $client_ip = undef; #How does one ask for client IP? # debug printf "Client IP = %s\n", $client_ip; printf "URI = %s\n", $uri; printf "host = %s\n", $uri->host(); printf "path = %s\n", $uri->path(); printf "query = %s\n", $uri->query(); } ); $proxy->push_filter( request => $filter ); $proxy->start;


Thank you in advance for your help.

Replies are listed 'Best First'.
Re: Identify Client IP Address while using HTTP::Proxy
by almut (Canon) on Oct 07, 2009 at 13:38 UTC
    my $client_ip = $self->proxy->client_socket->peerhost();

    seems to do the job.  Alternatively, you could use

    my $client_ip = $request->header('x-forwarded-for');

    which is the header set by the proxy itself (unless disabled), using the above method...

Re: Identify Client IP Address while using HTTP::Proxy
by Anonymous Monk on Oct 07, 2009 at 13:14 UTC
    use Data::Dumper; print Dumper( $self, $headers, $request );