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

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

创新互联建站是一家企业级云计算解决方案提供商,超15年IDC数据中心运营经验。主营GPU显卡服务器,站群服务器,遂宁联通机房,海外高防服务器,成都机柜租用,动态拨号VPS,海外云手机,海外云服务器,海外服务器租用托管等。

#!/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!"

文章标题:shell脚本实现快速ping网段内的IP地址
URL网址:https://www.cdcxhl.com/article6/ihiiog.html

成都网站建设公司_创新互联,为您提供移动网站建设网站营销企业建站自适应网站品牌网站建设网站排名

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

搜索引擎优化