LWP::UserAgent and non-default outgoing IP

T

Tomek

Hello!
My box on which Perl runs has several IPs, let's say that:

192.168.0.1 is the first IP and the default one,
192.168.0.5 is the last IP

How to force LWP::UserAgent to connect to remote hosts from IP 192.168.0.3
? I couldn't find it in the manual of LWP :(

Now, it always connects from the first and default IP: 192.168.0.1 :( How
to bind other outgoing address?

Regards, Tomasz Kraus
 
B

Ben Morrow

Quoth Tomek said:
Hello!
My box on which Perl runs has several IPs, let's say that:

192.168.0.1 is the first IP and the default one,
192.168.0.5 is the last IP

How to force LWP::UserAgent to connect to remote hosts from IP 192.168.0.3
? I couldn't find it in the manual of LWP :(

Now, it always connects from the first and default IP: 192.168.0.1 :( How
to bind other outgoing address?

You can set the variable @LWP::protocol::http::EXTRA_SOCK_OPTS to some
extra options to pass to every socket created for http communication. I
can't see with a quick look how to do the same for https/ftp, but this
may be enough for your problem.

Ben
 
R

Randal L. Schwartz

Tomek> How to force LWP::UserAgent to connect to remote hosts from IP
Tomek> 192.168.0.3 ? I couldn't find it in the manual of LWP :(

Tomek> Now, it always connects from the first and default IP: 192.168.0.1 :(
Tomek> How to bind other outgoing address?

The secret is in the source code of LWP::protocol::http. See the
@EXTRA_SOCK_OPTS variable defined there, and note how it is used. I'm not
sure why it's not documented... maybe it's not well tested yet. But it works.

print "Just another Perl hacker,"; # the original!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,201
Messages
2,571,049
Members
47,655
Latest member
eizareri

Latest Threads

Top