Shell script-how to scan all IP addresses of a specified network segment before the business goes online?

1. Why use this script

  • The script in this chapter can scan all the IP addresses in the network segment you set before the business goes online, and you can check which addresses are not occupied, avoiding waste of resources

Second, the realization process

  • Through the for loop, ping the test ip address all the time. Assuming that the public 254 addresses of the class C network segment are used, it will traverse from 1 to 254, and then exit the loop to end the script

Three, script

#!/bin/bash
# 扫描192.168.1.网段中的从1遍历到254个地址
ip=192.168.1.
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/F2001523/article/details/112258760