shell多线程快速检测内网ip是否存活
之前写了一篇shell检测内网ip是否存活,对内网ip检测实在是太慢了,最近闲得蛋疼,决定用多进程来解决.
#!/bin/bash # By rocdk890 # https://blog.slogra.com #Check the network is online cat /dev/null > ip_yes.txt cat /dev/null > ip_no.txt ip_num="192.168.1" read -p "Enter your network segment(Default ip: 192.168.1):" ip_num if [ "$ip_num" = "" ];then ip_num="192.168.1" 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
ps:如果觉得屏幕输出结果有点乱的话,可以去看两个txt文件里的结果,我做了排序的.
评论: