检查网络连通情况
关键词:ping 方法一: #!/bin/bash function Check_Network(){ check=$( cat /root/tansk/hostname.txt ) for ip in $check do ping -c 4 -i 0.2 -w 3 $ip &> /dev/null; if [ $? -eq 0 ] ; then echo "host $ip online!"; else echo "host $ip offline!"; fi done } Check_Network; 效果: [root@test tansk]# ./test.sh host www.baidu.com offline! host 192.168.247.100 online! host 8.8.8.8 online! host 192.168.247.2 online! host 192.168.247.200 offline! [root@test tansk]# 方法二: #!/bin/bash echo "请输入IP:" times=0 while true do let times++ read ip echo "计数:$times " ping -c 4 -i 0.2 -w 3 $ip &> /dev/null if [ $? -eq 0 ] then echo