!/bin/bash
#Check the network is online
cat /dev/null > ip_yes.txt
cat /dev/null > ip_no.txt
ip_num="192.168.0"
read -p "Enter your network segment(Default ip: 192.168.0):" ip_num
if [ "$ip_num" = "" ];then
ip_num="192.168.0"
fi
echo "Please wait..."
for i in seq 1 254
do
{
ping -c2 -s1 $ip_num.$i >/dev/null
if [ $? -eq 0 ];then
echo -e $ip_num.$i is "\033[32;49;1mup\033[39;49;0m"
echo -e "$ip_num.$i is up" >> ip_yes.txt
else
echo -e $ip_num.$i is "\033[40;31mdown\033[40;37m"
echo -e "$ip_num.$i is down" >> ip_no.txt
fi
}&
done
wait
sort -n -k 4 -t . ip_yes.txt -o ip_yes.txt
sort -n -k 4 -t . ip_no.txt -o ip_no.txt
原文地址:https://blog.51cto.com/13293070/2446709
时间: 2024-10-12 10:35:18