Ping 1000个包看丢跑率

41 篇文章 30 订阅 ¥39.90 ¥99.00
这段Perl脚本使用Net::Ping模块发送1000个ICMP请求到指定主机,计算丢包率。它首先检查参数,然后初始化计数器,接着对目标主机进行ping操作,根据ping响应更新存活和丢失包计数。最后输出结果。
摘要由CSDN通过智能技术生成
<pre name="code" class="sql">use warnings;    
use Net::Ping;  
 $J=0;
 $K=0;
for ($i = 1;$i <= 1000;$i++){  
if ($#ARGV <0){    
   print "请输入一个参数\n";    
  exit(-1);    
}    
$host = $ARGV[0];    
$p = Net::Ping->new("icmp");
  if ($p->ping($host,5)){$J++ }
  
 
else{$K++}


 $p->close();    
 #sleep(1);
 print "$host  alive is $J\n";
print "$host  lost is $K\n";
}



##第二个参数为默认超时值($def_timeout),以秒为单位,设置此值是为了定义PING方法的超时值,默认为5秒

##第二个参数为默认超时值($def_timeout),以秒为单位,设置此值是为了定义PING方法的超时值,默认为5秒



 If a default timeout ($def_timeout) in seconds is provided, it is
        used when a timeout is not given to the ping() method (below). The
        timeout must be greater than 0 and the default, if not specified, is
        5 seconds


$p->ping($host [, $timeout]);
        Ping the remote host an
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

scan724

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值