Showing posts with label proxy. Show all posts
Showing posts with label proxy. Show all posts

Saturday, July 18, 2009

Perl: Using LWP with a SOCKS Proxy

For this example, we'll use LWP to connect through a SOCKS proxy to the Tor anonymizing network. Under Ubuntu/Debian, installation of Tor is as simple as:
sudo apt-get install tor
Next, install the LWP::Protocol::socks Perl module to add support for the "socks" scheme. Installing from CPAN:
sudo cpan LWP::Protocol::socks
You should now be able to use LWP with Tor:

#!/usr/bin/perl
use strict;
use LWP::UserAgent;

my $ua = LWP::UserAgent->new(
agent => q{Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; YPC 3.2.0; .NET
CLR 1.1.4322)},
);
$ua->proxy([qw/ http https /] => 'socks://localhost:9050'); # Tor proxy
$ua->cookie_jar({});
my $rsp = $ua->get('http://www.yahoo.com/');
print $rsp->content;