> I'm using the LWP, HTML::Parser, HTTP::Request::Common and other packages
> retrieve some infromation from some web sites which require I have a certain
> IP address. I'm using a VPN to connect to this network. How can I tell perl
> to use the secondary IP address aquired by means of the VPN instead of my
> primary?


It *can* be done entirely within Perl, but with considerable
difficulty.

At the kernel level, when you open a socket, you usually leave the
'local' end anonymous, allowing the kernel to choose the appropriate
address based on the destination network.

Now, it turns out that IO::Socket::INET allows you, at socket
construction time, to pass in a LocalAddr argument, which will
override this default behavior.

IO::Socket::INET is inherited by Net::HTTP, which is in turn inherited
by LWP::Protocol::http::Socket and the knee bone is connected to the
shin bone ...

The little glitch is:  The constructors up in LWP::UserAgent don't
really give you enough flexibility to specify that.  

You actually could subclasss LWP::Protocol::http into some private
class LWP::Protocol::vpnhttp and change the implementor binding in
LWP::Protocol - then, in your subclass vpnhttp implement nothing but
the _extra_sock_opts() method to set the lcoal local binding as
appropriate.

The ***MUCH** less painful solution would be, rather than force the
binding at the Perl level, is fix the routing at your kernel level --
such that for hosts that ought to be reached via the VPN, the
preferred route will be, in fact, via the VPN.  A few minutes with
"route add net..."  should solve that problem -- with the side benefit
that ALL applications will use the new-correct route and not try to go
"the long way around"

Good luck.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to