2015-01-04 35 views
1
#!/usr/bin/perl 

use strict; 
use LWP::UserAgent; 

my $ua = new LWP::UserAgent(agent => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.5) Gecko/20060719 Firefox/1.5.0.5'); 
$ua->proxy('http' => 'socks://188.26.223.189:1080'); 
my $response = $ua->get('http://example.com'); 
print $response->code,' ', $response->message,"\n"; 
print $response->decoded_content . "\n"; 

我试着通过袜子代理连接到网站,但我得到的错误:500无法连接到example.com:80 我错了呢?不能老是连接通过SOCKS代理托管在Perl

+0

你有Perl模块,[LWP ::协议::袜子(https://metacpan.org/pod/LWP :: Protocol :: socks)安装? –

+0

是的,我安装了它。 – Artem

+0

看一下[this](http://mlawire.blogspot.com/2009/07/using-lwp-with-tor.html)。除了'[qw/http https /]'外,它看起来差不多。 –

回答

1

这可能意味着以下三种情况之一:

  1. 您在188.26.223.189:1080代理不起作用
  2. example.com不起作用
  3. example.com不起作用for 188.26.223.189

LWP::Protocol::socks使用IO::Socket::Socks作为SOCKS库。所以,你可以通过定义SOCKS_DEBUG环境变量打开调试:

SOCKS_DEBUG=1 perl test.pl 

这将告诉你一个SOCKS握手。所以你可能会看到这次握手成功与否(https://www.ietf.org/rfc/rfc1928.txt)。

你也可以尝试直接通过IO::Socket::Socks连接,看看会通向成功:

perl -MIO::Socket::Socks -E 'IO::Socket::Socks->new(ProxyAddr => "188.26.223.189", ProxyPort => 1080, ConnectAddr => "example.com", ConnectPort => 80, Timeout => 30, SocksDebug => 1) or die $SOCKS_ERROR; say "Connected!"'