Guest User

Check.pl

a guest
Jan 27th, 2014
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.80 KB | None | 0 0
  1. use 5.010;
  2. use strict;
  3. use warnings;
  4. use Carp;
  5. use FindBin;
  6. use lib "$FindBin::Bin/../lib";
  7. use File::Slurp qw/write_file/;
  8. use List::Util qw/shuffle/;
  9. use Getopt::Long qw/GetOptions/;
  10. use Attack;
  11. use Attack::LWP;
  12. use Attack::Coro;
  13. my $opt = {
  14. infile => 'unchecked.txt',
  15. outfile => 'checked.txt',
  16. url => 'http://4pda.ru',
  17. referer => 'http://4pda.ru',
  18. threads => 500,
  19. time => 30,
  20. attempts => 5,
  21. wait => 3,
  22. };
  23. Carp::croak "Can't find proxies file '$opt->{infile}'" unless -f $opt->{infile};
  24. my @proxies = Attack::read_proxylist($opt->{infile});
  25. my @ignore = Attack::read_proxylist($opt->{outfile}) if -f $opt->{outfile};
  26. @proxies = grep { not $_ ~~ @ignore } @proxies;
  27. @proxies = shuffle @proxies;
  28. my @result;
  29. my $w = new Attack::Coro::Watcher;
  30. while(my @part = splice @proxies, 0, 1000) {
  31. my $threads = new Attack::Coro::Pool(
  32. debug => 1,
  33. desc => "check",
  34. timelimit => $opt->{time},
  35. limit => $opt->{threads},
  36. params => \@part,
  37. function => \&check_func,
  38. );
  39. $threads->start_all;
  40. $threads->join_all;
  41. undef $threads;
  42. }
  43. write_file($opt->{outfile}, { append => 1 }, join("\n", @result) . "\n");
  44. sub check_func {
  45. my($proxy) = @_;
  46. my $lwp = new Attack::LWP;
  47. $lwp->referer($opt->{referer}) if $opt->{referer};
  48. $lwp->agent("Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.76 Safari/537.36");
  49. $lwp->proxy($proxy);
  50. for(1 .. $opt->{attempts}) {
  51. my $response = $lwp->get($opt->{url});
  52. if( $response->is_success) {
  53. push @result, $proxy;
  54. if(@result >= 5) {
  55. write_file($opt->{outfile}, { append => 1 }, join("\n", @result) . "\n");
  56. @result = ();
  57. }
  58. return $proxy . ": " . sprintf("+ %s +", $response->status_line);
  59. } elsif($_ >= $opt->{attempts}) {
  60. return $proxy . ": " . $response->status_line;
  61. } else {
  62. Coro::AnyEvent::sleep $opt->{wait};
  63. }
  64. }
  65. return;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment