Testare una lista di proxy in Perl con i threads
INPUT FILE NAME: proxy
INPUT FILE FORMAT: 1 IP:PORTA per ogni riga del file
OUTPUT LOG FILE NAME: proxy.log
VARS:
$nn -> numero di richieste per volta
$timeout -> tempo massimo di attesa per le $nn richieste
SOURCE: http://pastebin.com/8GejbgjD
#!/usr/bin/perl -w
use threads;
use WWW::Mechanize;
$nn = 25; # number of simultaneous connections
$timeout = 10; # proxy request timeout (secs)
sub start_thread {
my @args = @_;
my $go = WWW::Mechanize->new( agent=> "Mozilla/5.0", timeout => $timeout);
$go->proxy(['http'], 'http://'.$args[0].'/');
print "Testing: ".$args[0]."\n";
eval {
$go->get('http://automation.whatismyip.com/n09230945.asp');
};
if ($@) { return; }
$match = $go->content;
my($crap,$ip)=split(/^(.*):/,$args[0]);
if ($match =~ /$ip/) {
open(LOG,">> proxy.log"); print LOG $args[0]."\n"; close(LOG);
print "======> UP $args[0] <=======\n";
}
}
@proxy=`cat proxy`;
$n = 0;
foreach $i (@proxy) {
chomp($i);
$thr[$n] = threads->create('start_thread', $i);
$n++;
if ($n == $nn) {
`sleep $timeout`;
for ($x=0; $x<$nn;$x++) {
$thr[$x]->join();
}
$n = 0;
}
}


