Linux shell实现ping ip是否在线-2

Linux实现ping ip是否在线shell

#!/bin/bash
str="192.168.11."
for num in {1..25}
do
ip=${str}${num}

ping -c1 -w1 ${ip} &>/dev/null 

if [ $? -eq 0 ];then
	echo "$ip is online"
	echo $ip >>/root/online.txt
else
	echo "$ip is offline"
	echo $ip >> /root/offline.txt
fi
done
online=`cat /root/online.txt |wc -l`
offline=`cat /root/offline.txt|wc -l`

echo "目前在线的IP总数为$online"
echo "目前不在线的IP总数为$offline"

验证输出:

[root@patrolagent ~]# sh ping.sh 
192.168.11.1 is offline
192.168.11.2 is offline
192.168.11.3 is offline
192.168.11.4 is offline
192.168.11.5 is offline
192.168.11.6 is offline
192.168.11.7 is offline
192.168.11.8 is offline
192.168.11.9 is offline
192.168.11.10 is offline
192.168.11.11 is offline
192.168.11.12 is offline
192.168.11.13 is offline
192.168.11.14 is offline
192.168.11.15 is offline
192.168.11.16 is offline
192.168.11.17 is offline
192.168.11.18 is offline
192.168.11.19 is offline
192.168.11.20 is offline
192.168.11.21 is offline
192.168.11.22 is offline
192.168.11.23 is offline
192.168.11.24 is offline
192.168.11.25 is offline
cat: /root/online.txt: No such file or directory
目前在线的IP总数为0
目前不在线的IP总数为25
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

小黑要上天

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

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

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

打赏作者

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

抵扣说明:

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

余额充值