use HTTP::UserAgent;
my $fp = open 'result.txt', :w;
my @threads; #控制线程数目
sub MAIN (Str $ip, Str $dict) {
#
#判断是否是文件
if $dict.IO.f {
#不要把文件一次进数组, 一行一行读就行
for $dict.IO.lines -> $line {
push @threads, start {
#拼接url
my $ua = HTTP::UserAgent.new;
my $target = $ip~'/'~$line;
say 'Fetch: '~$target;
my $html = $ua.get($target);
#查看状态码
#say $html.status-line;
$fp.say($target => $html.status-line) if $html.status-line ~~ /200/;
};
#控制线程 数
if @threads == 4 {
await Promise.anyof(@threads);
@threads .= grep({!$_});
}
}
}else {
say $dict~' Not exists or not a file!';
#不是文件或不存在就提示
}
await @threads;
}