Perl使用Net::Ping

use warnings;
use Net::Ping;
if ($#ARGV <0){
   print "请输入一个参数
";
  exit(-1);
}
$var=$ARGV[0];
@ARRAY="";
for ($i = 1;$i<=255;$i++){
push  @ARRAY, "$var.$i"};
foreach $host (@ARRAY){
$p = Net::Ping->new("icmp");
# print "$host is alive.
" if $p->ping($host,5);
print "$host is ";
print "lost " unless $p->ping($host, 2);
print "reachable.
";
$p->close();
#sleep(1);
}

原文地址:https://www.cnblogs.com/hzcya1995/p/13351971.html