Use proxy with perl script

后端 未结 3 1058
青春惊慌失措
青春惊慌失措 2021-01-06 11:12

I want to use a proxy with this perl script but I\'m not sure how to make it use a proxy.

#!/usr/bin/perl
use IO::Socket;
$remote = IO::Socket::INET->new(         


        
3条回答
  •  醉话见心
    2021-01-06 11:44

    Straight from one of my scripts:

    use LWP::UserAgent;
    my($ua) = LWP::UserAgent->new;
    
    if ($opts->{'proxy'}) {
        my($ip) = Sys::HostIP->hostip;
        if (($ip =~ m{^16\.143\.}) ||
            ($ip =~ m{^161\.}) ||
            ($ip =~ m{^164\.})) {
            $ua->proxy(http  => 'http://localhost:8080');
        }
        else {
            $ua->proxy(http  => "");
        }
    }
    else {
        $ua->env_proxy;
    }
    
    #***** get current entry *****
    my($req) = HTTP::Request->new(GET => "http://stackoverflow.com/questions/1746614/use-proxy-with-perl-script");
    my($raw) = $ua->request($req)->content;
    

提交回复
热议问题