in reply to Re: LWP Request Through SOCKS Proxy
in thread LWP Request Through SOCKS Proxy
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(); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: LWP Request Through SOCKS Proxy
by salva (Canon) on Apr 20, 2005 at 09:21 UTC | |
|
Re^3: LWP Request Through SOCKS Proxy
by salva (Canon) on Apr 19, 2005 at 08:47 UTC |