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

Straight to the point. Here's my code...

$ua = LWP::UserAgent->new; $cookie_jar = HTTP::Cookies->new(file => "cookies.dat"); $ua->cookie_jar($cookie_jar); $header = new HTTP::Headers (Accept => 'text/html'); $request = HTTP::Request->new(GET, $page, $header); $response = $ua->request($request);

This code works fine, but the problem is that my application is hosted on my server for use by my clients and the REMOTE_ADDR environment variable which is passed by the ua is *my* machine but it needs to be my *clients'* REMOTE_ADDR as they are the one that really needs to be identified as making the request.

Two questions here...

1) How can I get the ua to pass my client's REMOTE_ADDR?

2) Are there any alternate approaches to this problem?

TIA for any wisdom :-)

Jeff

Replies are listed 'Best First'.
Re: LWP User Agent Difficulty
by dws (Chancellor) on Aug 10, 2002 at 15:48 UTC
    1) How can I get the ua to pass my client's REMOTE_ADDR?

    Strictly speaking, you can't. The web server at the other end of the request your UserAgent is making gets the IP address off of the socket. Without serious, OS-level magic, you can't forge that IP addr.

    What you can do is to take the REMOTE_ADDR that your UserAgent sees, and either

    • create a cookie with it, to be passed to $url
    • add it to a form that you'll send to $url
    • append it to $url (e.g., "$url/$ENV{REMOTE_ADDR}") to be passed in PATH_INFO.

    All of these require that the CGI represented by $url cooperate.

      Okay, if I add it to $url as you suggest -- How do I return the desired end result AKA the page I really need the UA to return
Re: LWP User Agent Difficulty
by kschwab (Vicar) on Aug 10, 2002 at 15:46 UTC
    1) You can't. The web server is using getpeername() or something similar to find the endpoint of the socket, and then making it available to cgi-bin programs. This makes it a somewhat trustworthy source of where the client is coming from.

    2) I'm not clear why you need to do that. I suppose you could set up a squid proxy on the client's machine and route your requests through it.