zoukankan      html  css  js  c++  java
  • perl多线程ping检测C段存活主机

    看了一些前辈的多线程文章,感觉理解了差不多了。就写了这个小程序。

    这个程序有点乱,不过没有时间整理写注释,回头有空写成mode吧。

    #!/usr/bin/perl
    use threads;
    use Net::Ping;
    
    $p=Net::Ping->new();
    sub slep_ping{
      local($host_ip)=shift;
      if($p->ping($host_ip))
      {
         print "$host_ip is access---------OK!\n";
      }else{
         print "$host_ip is No access\n";
      }
      $p->close();
    }
    
    sub ip_count{
      while($ip_start != $ip_end){
        push @ip_group,("$ip."."$ip_start");
        $ip_start++;
      }
      return @ip_group;
    }
    
    system('clear');
    print "please set the IP(C):";
    chomp($ip=<STDIN>);
    print "StartIP:";
    chomp($ip_start=<STDIN>);
    print "EndIP:";
    chomp($ip_end=<STDIN>);
    
    my $thread_num=0;
    &ip_count;
    foreach $key (@ip_group){
       if($thread_num >= 200){
            for my $t (threads->list(threads::joinable)){
                   $t->join();
                   $thread_num--;
            }
            redo;
       }
       threads->create(\&slep_ping,$key);
       $thread_num++;
    }
    for my $t(threads->list()){
       $t->join;
    }
    
  • 相关阅读:
    备份
    Android资料之-EditText中的inputType
    trim() 是什么意思?
    两数相加
    点击edittext并显示其内容
    php 返回上一页并刷新
    sql one
    sql 语句 查询两个字段都相同的方法
    我为什么喜欢Go语言123123
    数据字典
  • 原文地址:https://www.cnblogs.com/xiaoCon/p/2931785.html
Copyright © 2011-2022 走看看