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;
    }
    
  • 相关阅读:
    今日SGU 5.27
    今日SGU 5.26
    今日SGU 5.25
    软件工程总结作业
    个人作业——软件产品案例分析
    个人技术博客(α)
    结对作业二
    软工实践 二
    软工实践 一
    《面向对象程序设计》六 GUI
  • 原文地址:https://www.cnblogs.com/xiaoCon/p/2931785.html
Copyright © 2011-2022 走看看