扫描局域网ip的shell

时间:2025-03-08 12:03:38
# vim /mysh/ipscan.sh 

#!/bin/bash
# scan the local alive ipaddress
# -- if [ -f $filename ];then
echo "the file is exist"
for n in {..};do
host=192.168..$n
ping -c2 $host &>/dev/null
if [ $? = ];then
echo "$host is up"
echo "$host" >> /root/alive.txt
else
echo "$host is Down"
fi
done
echo "------------------`date +"%Y-%m-%d"`-------------------------------"
else
echo "the file is not exist"
touch /root/alive.txt
fi