如何在perl中使用一个互联网连接



我有两个互联网连接wlan0和eth0,我只想在wlan0中运行此脚本。

#!/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 upn";
    }
    else {
        print "- Google is downn";
        $ok = 0;
        last;
    }
    sleep 1;
}
if ($ok) {
    print "Result: Google is OK!n";
}
else {
    print "Result: Google is not OK!n";
}

如何将其编码为仅使用wlan0互联网。这在perl脚本中是可行的吗?

你可以试试这个破解

@LWP::Protocol::http::EXTRA_SOCK_OPTS = (LocalAddr => $source_ip);

最新更新