use warnings;
use Net::Ping;
if ($#ARGV <0){
print "请输入一个参数\n";
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.\n" if $p->ping($host,5);
print "$host is ";
print "lost " unless $p->ping($host, 2);
print "reachable.\n";
$p->close();
#sleep(1);
}
Perl使用Net::Ping
最新推荐文章于 2017-11-16 20:10:00 发布
该博客介绍了如何使用Perl的Net::Ping模块进行ICMP ping操作。通过读取命令行参数并结合循环,对指定IP地址段进行ping检查,判断目标主机是否可达。示例代码展示了如何创建ping对象,执行ping请求以及处理结果。
摘要由CSDN通过智能技术生成