【问题标题】:Can`t connect to host via socks proxy in perl无法通过 perl 中的 socks 代理连接到主机
【发布时间】:2015-01-04 19:14:18
【问题描述】:
#!/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";

我尝试通过 socks-proxy 连接到网站,但出现错误:500 Can't connect to example.com:80 我做错了什么?

【问题讨论】:

  • 你安装了Perl模块LWP::Protocol::socks吗?
  • 是的,我安装了它。
  • 看看this。除了[ qw/http https/ ],它看起来几乎一样。
  • 这也行不通。
  • 当。我希望这里能出现奇迹。看看你是否可以“telnet”到代理($ telnet 188.26.223.189 1080)。我想知道您是否需要代理上的用户名和密码?

标签: perl sockets socks lwp


【解决方案1】:

这可能意味着以下三件事之一:

  1. 您在 188.26.223.189:1080 的代理不起作用
  2. example.com 不起作用
  3. example.com 不适用于 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!"'

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-18
    • 1970-01-01
    • 1970-01-01
    • 2017-08-08
    • 2017-02-08
    • 2021-01-19
    相关资源
    最近更新 更多