加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

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

发布时间:2020-12-15 07:17:21 所属栏目:安全 来源:网络整理
导读:题目如下: #!/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=2
题目如下:

#!/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
测试结果:

这个脚本主要运用到了循环语句,条件判断,如IP地址的取值范围,变量的赋值等进行判断,使用if语句和while语句结合起来达到效果,还有排序等知识点,在以后的网络中的运用也是很广泛的

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读