Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use 5.010;
- use strict;
- use warnings;
- use Carp;
- use FindBin;
- use lib "$FindBin::Bin/../lib";
- use File::Slurp qw/write_file/;
- use List::Util qw/shuffle/;
- use Getopt::Long qw/GetOptions/;
- use Attack;
- use Attack::LWP;
- use Attack::Coro;
- my $opt = {
- infile => 'unchecked.txt',
- outfile => 'checked.txt',
- url => 'http://4pda.ru',
- referer => 'http://4pda.ru',
- threads => 500,
- time => 30,
- attempts => 5,
- wait => 3,
- };
- Carp::croak "Can't find proxies file '$opt->{infile}'" unless -f $opt->{infile};
- my @proxies = Attack::read_proxylist($opt->{infile});
- my @ignore = Attack::read_proxylist($opt->{outfile}) if -f $opt->{outfile};
- @proxies = grep { not $_ ~~ @ignore } @proxies;
- @proxies = shuffle @proxies;
- my @result;
- my $w = new Attack::Coro::Watcher;
- while(my @part = splice @proxies, 0, 1000) {
- my $threads = new Attack::Coro::Pool(
- debug => 1,
- desc => "check",
- timelimit => $opt->{time},
- limit => $opt->{threads},
- params => \@part,
- function => \&check_func,
- );
- $threads->start_all;
- $threads->join_all;
- undef $threads;
- }
- write_file($opt->{outfile}, { append => 1 }, join("\n", @result) . "\n");
- sub check_func {
- my($proxy) = @_;
- my $lwp = new Attack::LWP;
- $lwp->referer($opt->{referer}) if $opt->{referer};
- $lwp->agent("Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.76 Safari/537.36");
- $lwp->proxy($proxy);
- for(1 .. $opt->{attempts}) {
- my $response = $lwp->get($opt->{url});
- if( $response->is_success) {
- push @result, $proxy;
- if(@result >= 5) {
- write_file($opt->{outfile}, { append => 1 }, join("\n", @result) . "\n");
- @result = ();
- }
- return $proxy . ": " . sprintf("+ %s +", $response->status_line);
- } elsif($_ >= $opt->{attempts}) {
- return $proxy . ": " . $response->status_line;
- } else {
- Coro::AnyEvent::sleep $opt->{wait};
- }
- }
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment