用于测试指定段的主机的连通性的脚本

前端之家收集整理的这篇文章主要介绍了用于测试指定段的主机的连通性的脚本前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
题目如下:@H_404_1@

#!/bin/bash
#thescript'snameis:*********usetotestthehost*********
#theauthoris:Ro
#theversionis:Ro-4-10
letPIP=$1
NetIP='192.168.1.'
if[$1-gt254];then
echo"Thefistnumbershould<=254"
elif[$2-gt254];then
echo"Thesecondnumbershould<=254"
elif[$1-gt$2];then
echo"Thefirstnumbershould<=thesecondnumber"
else
while[$PIP-le$2];do
ping-c1-W1$NetIP$PIP>/dev/null&&echo"Thehost$NetIP$PIPisUP.">>/tmp/host_state||echo"Thehost$NetIP$PIPisDOWN.">>/tmp/host_state
letPIP++
done
echo"=============================="
cat/tmp/host_state
echo"=============================="
sed'1,$s/\(.*DOWN\)./#\1/g'/tmp/host_state
echo"=============================="
sort-t""-k5/tmp/host_state|cut-d""-f5|uniq-c
echo"=============================="
rm-rf/tmp/host_state
fi
测试结果:@H_404_1@这个脚本主要运用到了循环语句,条件判断,如IP地址的取值范围,变量的赋值等进行判断,使用if语句和while语句结合起来达到效果,还有排序等知识点,在以后的网络中的运用也是很广泛的

猜你在找的Shell相关文章