shell脚本——业务上线前扫描网段内所有ip地址

一、前言

  • 当业务上线之前,扫描ip地址,那些地址没有没占用。
  • 通过for循环,一直ping测试IP地址,假设咱们C类网段公有254个地址,从1遍历到254

二、上脚本

#!/bin/bash
ip=192.168.10.
for((a=1;a<=254;a++))
do
  b=${ip}${a}
  ping -c 3 -i 0.2 -w 3  $b  &>> /dev/null
if [ $? -eq 0 ]
then
    echo "host $a is up" &>>up.txt
else
    echo "host $a is down" &>>down.txt
fi
done

猜你喜欢

转载自blog.csdn.net/m0_46563938/article/details/108765189