I have 2 internet connection wlan0 and eth0 and I want to run this script in wlan0 only.
#!/usr/bin/perl
use LWP::UserAgent;
my $ua = LWP::UserAgent->new( timeout => 1 );
$ua->agent("007");
my $req = HTTP::Request->new( GET => 'http://120.28.53.178/favicon.ico' ); # HTTP::Request in wlan0 connection
my $ok = 1;
my $res;
for ( 1 .. 10 ) {
$res = $ua->request($req);
if ( $res->is_success ) {
print "+ Google is up\n";
}
else {
print "- Google is down\n";
$ok = 0;
last;
}
sleep 1;
}
if ($ok) {
print "Result: Google is OK!\n";
}
else {
print "Result: Google is not OK!\n";
}
How can I code it to use wlan0 internet only. This is posible in perl script?
您可以尝试这个技巧
@LWP::Protocol::http::EXTRA_SOCK_OPTS = (LocalAddr => $source_ip);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.