Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^3: How to specify outlet interface for LWP?

by Anonymous Monk
on May 25, 2009 at 06:41 UTC ( [id://765971]=note: print w/replies, xml ) Need Help??


in reply to Re^2: How to specify outlet interface for LWP?
in thread How to specify outlet interface for LWP?

Doesn't work... It seems that there is no way to specify an interface for LWP

?? bullpucky

#!/usr/bin/perl -- use strict; use warnings; use LWP 5.826; use LWP::Protocol::http; #perldoc -q "How do I find out my hostname/domainname/IP address?" use Socket; use Sys::Hostname; my $host = hostname(); my $addr = inet_ntoa(scalar gethostbyname($host || 'localhost')); my $ua = LWP::UserAgent->new(); { print "# works like default\n"; local @LWP::Protocol::http::EXTRA_SOCK_OPTS = ( LocalAddr => $addr ) +; print $ua->get("http://www.example.com")->status_line,"\n"; } { print "# bad hostname\n"; local @LWP::Protocol::http::EXTRA_SOCK_OPTS = ( LocalAddr => "nohost +:666" ); print $ua->get("http://www.example.com")->status_line,"\n"; } { print "# unknown error\n"; local @LWP::Protocol::http::EXTRA_SOCK_OPTS = ( LocalAddr => "localh +ost" ); print $ua->get("http://www.example.com")->status_line,"\n"; printf "$^E\n"; } __END__ # works like default 200 OK # bad hostname 500 Can't connect to www.example.com:80 (Bad hostname 'nohost:666') # unknown error 500 Can't connect to www.example.com:80 (connect: Unknown error) A connection attempt failed because the connected party did not proper +ly respond after a period of time, or established connection failed because connected host has failed to respond

Replies are listed 'Best First'.
Re^4: How to specify outlet interface for LWP?
by sunshine_august (Scribe) on May 25, 2009 at 06:49 UTC
    oh, yes, it works now, there is some bug in my script break the lwp part, now I fix it, and it works fine for me. Thanks and sorry for my mistake:).

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://765971]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (2)
As of 2024-04-20 04:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found