shell多线程快速检测内网ip是否存活

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

上一篇:C 语言输出不同颜色字体


下一篇:正整数进制转换脚本