You can just open a local socket and have it connect to the SOCKS server. So you give LWP an address like http://localhost:8080/.
use strict; use Net::SOCKS; use IO::Select; use Fcntl; sub nonblock { my $socket = shift; my $flags = fcntl($socket, F_GETFL, 0) or die "Can't get flags for socket: $!"; fcntl($socket, F_SETFL, $flags | O_NONBLOCK) or die "Can't set flags for socket: $!"; } { my $sock = new Net::SOCKS(socks_addr => '127.0.0.1', socks_port => 1080, protocol_version => 4) || die; print "sock $sock\n"; my $server = new IO::Socket::INET(Listen => 1, Reuse => 1, LocalAddr => 'localhost', LocalPort => 8080, Proto => 'tcp', ); my $clients = {}; my $socks = {}; eval { while (1) { my $select = new IO::Select( $server ); my $ok = 1; my %hash; while ($ok) { foreach my $sel ($select->can_read(1)) { if ($sel == $server) { my $client = $server->accept(); $select->add($client); print "client $client\n"; my $f = $sock->connect(peer_addr => 'www.google.co +m', peer_port => 80); $clients->{$client} = $f; $socks->{$f} = $client; $select->add($f); print "socks $f\n"; } elsif (my $client = $clients->{$sel}) { my $char; $sel->sysread($char, 80); unless (length($char)) { printf "close\n"; $select->remove($sel); delete $clients->{$sel}; $sel->close; next; } my $x = $client; print $x $char; } elsif (my $socks = $socks->{$sel}) { my $char; $sel->sysread($char, 1); unless (length($char)) { printf "close\n"; $select->remove($sel); delete $clients->{$sel}; $sel->close; next; } print $socks $char; } else { print "sel $sel\n"; } } } print "EXIT\n"; } }; if ($@) { print $@; } $sock->close(); }
Update: added code sample
-- gam3
A picture is worth a thousand words, but takes 200K.

In reply to Re^2: LWP Request Through SOCKS Proxy by gam3
in thread LWP Request Through SOCKS Proxy by geekondemand

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.