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

I am using LWP::UserAgent and HTTP::Request::Common to download some Web pages. My computer has several IP addresses, so I'd like my HTTP request to originate from one of them (technically speaking, the outgoing connection should bind to an address of my choice). But i can't seem to find any functions to do that. I know that in PHP/curl it is achieved by using CURLOPT_HTTPINTERFACE, but how do I do that in Perl with LWP::UserAgent?
  • Comment on HTTP::Request::Common - how to bind to specific IP address?

Replies are listed 'Best First'.
Re: HTTP::Request::Common - how to bind to specific IP address?
by ikegami (Patriarch) on Apr 06, 2006 at 07:10 UTC
    I dug into the source, and I found @LWP::Protocol::http::EXTRA_SOCK_OPTS. I think (untested) the following will do the trick:
    push(@LWP::Protocol::http::EXTRA_SOCK_OPTS, LocalHost => ... );

    The value for LocalHost can be an IP address or a domain name.

      Current version of LWP::UserAgent has local_address function for this purpose.