perl多线程ping检测C段存活主机
发布时间:2020-12-16 00:02:17 所属栏目:大数据 来源:网络整理
导读:看了一些前辈的多线程文章,感觉理解了差不多了。就写了这个小程序。 这个程序有点乱,不过没有时间整理写注释,回头有空写成mode吧。 #!/usr/bin/perluse threads;use Net::Ping;$p=Net::Ping-new();sub slep_ping{ local($host_ip)=shift; if($p-ping($hos
看了一些前辈的多线程文章,感觉理解了差不多了。就写了这个小程序。 这个程序有点乱,不过没有时间整理写注释,回头有空写成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 accessn"; } $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; } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |