Artem
Artem

Reputation: 553

Can`t connect to host via socks proxy in perl

#!/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";

I try to connect to website via socks-proxy, but I get error: 500 Can't connect to example.com:80 What I do wrong?

Upvotes: 1

Views: 1119

Answers (1)

Oleg G
Oleg G

Reputation: 945

This may mean one of three things:

  1. your proxy at 188.26.223.189:1080 doesn't work
  2. example.com doesn't work
  3. example.com doesn't work for 188.26.223.189

LWP::Protocol::socks uses IO::Socket::Socks as SOCKS library. So, you may turn on the debugging by defining SOCKS_DEBUG environment variable:

SOCKS_DEBUG=1 perl test.pl

This will show you a SOCKS handshake. So you may see was this handshake success or not (https://www.ietf.org/rfc/rfc1928.txt).

You may also try to connect directly through IO::Socket::Socks to see will it success:

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!"'

Upvotes: 1

Related Questions