shell脚本实现快速ping网段内的IP地址

发布时间:2020-07-28 13:01:25 作者:tutor
来源:网络 阅读:843

有时候想看看网段中有哪些IP被用了,可以用这个快速ping做一个初步的判断。可以自己指定测试IP网段,并将测试结果整理排序到文件。


#!/bin/bash

#V1.0 2019-09-10

#Ping test shell script by tutor


clear

>ip-up.txt

>ip-down.txt


while true;

 do

    read -p "Please input the ip segment for ping test(like 192.168.100) : "  segment



     if [ -z $segment  ] ; then


       segment="192.168.100"


     fi



    echo -n "the ip segment is ${segment} , are you sure to continue [y/n] ? "


    read  action


     if [ -z $action  ] ; then

          break

     fi


     if [  "$action" =  "y"  ]; then

         break

     fi

done


echo "ping test is ready to run! "


for i in  {1..254}

 do

      {

        ping -c2 -W1 ${segment}.${i}  &>/dev/null

        if [ $? -eq 0 ]; then

           echo "${segment}.$i is up" &>/dev/null  >> ip-up.txt

        else

           echo "${segment}.$i is down" &>/dev/null >> ip-down.txt

        fi

     }&

done


wait

            sort -n -k 4 -t . ip-up.txt -o ip-up.txt

            cat ip-up.txt

            sort -n -k 4 -t . ip-down.txt -o ip-down.txt

            cat ip-down.txt


echo "ping test are finished!"


推荐阅读:
  1. 检查某个网段存活的主机_shell脚本
  2. shell脚本ping -w用法

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

shell ping he

上一篇:Exchange-邮件组添加、删除成员

下一篇:TouchListener与OnclickListener

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》