Advertisement
st4ck

Perl Proxy Tester with Threads

Jan 24th, 2012
553
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.00 KB | None | 0 0
  1. #!/usr/bin/perl -w
  2. # Proxy list tester using threads
  3. #
  4. # INPUT file -> "proxy"
  5. # format -> IP:PORT on each row
  6. #
  7. # OUTPUT file -> "proxy.log"
  8.  
  9. use threads;
  10. use WWW::Mechanize;
  11.  
  12. $nn = 25; # number of simultaneous connections
  13. $timeout = 10; # proxy request timeout (secs)
  14.  
  15. sub start_thread {
  16.         my @args = @_;
  17.     my $go = WWW::Mechanize->new( agent=> "Mozilla/5.0", timeout => $timeout);
  18.     $go->proxy(['http'], 'http://'.$args[0].'/');
  19.     print "Testing: ".$args[0]."\n";
  20.     eval {
  21.      $go->get('http://automation.whatismyip.com/n09230945.asp');
  22.     };
  23.     if ($@) { return; }
  24.     $match = $go->content;
  25.     my($crap,$ip)=split(/^(.*):/,$args[0]);
  26.     if ($match =~ /$ip/) {
  27.         open(LOG,">> proxy.log"); print LOG $args[0]."\n"; close(LOG);
  28.         print "======> UP $args[0] <=======\n";
  29.     }
  30. }
  31.  
  32. @proxy=`cat proxy`;
  33. $n = 0;
  34. foreach $i (@proxy) {
  35. chomp($i);
  36. $thr[$n] = threads->create('start_thread', $i);
  37. $n++;
  38. if ($n == $nn) {
  39.  `sleep $timeout`;
  40.  for ($x=0; $x<$nn;$x++) {
  41.   $thr[$x]->join();
  42.  }
  43.  $n = 0;
  44. }
  45.  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement