zoukankan      html  css  js  c++  java
  • 目录扫描编写

    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;
    }
  • 相关阅读:
    生成器
    迭代器
    装饰器
    闭包函数
    函数对象
    函数
    文件
    字符编码
    基本的数据类型和内置方法02
    基本的数据类型和内置方法01
  • 原文地址:https://www.cnblogs.com/perl6/p/7447702.html
Copyright © 2011-2022 走看看