您的位置:首页 > 运维架构 > Shell

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

2019-10-31 11:14 2943 查看

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

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: