You are not logged in.
Pages: 1
#!/usr/bin/perl
use Socket;
use IO::Socket;
use Net::SOCKS;
use threads;
use threads::shared;
my ($host, $port) = @ARGV;
mfunc();
$port = 1080;
mfunc();
$port = 80;
mfunc();
for my $lthrd (1..7){
my $nthrd = threads->new(\&mfunc);
foreach (threads->list){
$_->join;
}
}
$port = 22;
mfunc();
sub mfunc{
eval {
local $SIG{ALRM} = sub { die "alarm\n" }; # NB \n required
alarm 7;
my $sock = new Net::SOCKS(socks_addr => $host, socks_port => $port, protocol_version => 4);
my $rsocks = $sock->connect(peer_addr => 'www.google.com', peer_port => 80);
my $status = $sock->param('status_num');
if ($status == SOCKS_OKAY){
print "\nWorked $host:$port\n";
$sock->close();
}
alarm 0;
};
die if $@ && $@ ne "alarm\n"; # propagate errors
if ($@) {
print("\nTimeout $host:$port\n");
}
}
Offline
Or switch to multiple processes instead of threads.
But yeah, if you're going to open many connections anyway I'd switch to
non-blocking sockets with multiplexing too.
Offline
Hi RobSeace and i3839
The bad news is that appear that select() doesn't work with Net::SOCKS in perl. Too bad!
How could make this process with multiple process instead threads? I mean, because in threads we share data, in multiple process (fork) I will have different instances repeating the same task, which for sure will not make my program posted on the thread to be fast as it's with threads.
Thank you
Offline
Umm, there is zero data sharing after thread creation in the code you posted.
Doing the same, but with fork should be hardly slower. You can still kill all
other childs if one of them gets a connection and you don't want the rest to do
anything.
There must be way to fish out the underlaying file descriptor/socket from
Net::SOCKS, so if you have a select or poll in perl it should work.
Offline
Pages: 1