Shell script-scan all IP addresses in the network segment before the business goes online

I. Introduction

  • Before the business goes online, scan the ip address, and those addresses are not occupied.
  • Through the for loop, keep pinging to test the IP address, assuming that our class C network segment has 254 public addresses, traversing from 1 to 254

Second, the script

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

Guess you like

Origin blog.csdn.net/m0_46563938/article/details/108765189