#!/bin/bash #writen by Jerry for i in `seq 1 255`; do { ping 192.168.51.$i -c 2 >> /dev/null 2>&1 #不管ping到ping不到都不在前臺顯示 tai=$(echo $?) if [ $tai == 0 ]; then echo -e "\033[1;32m 192.168.51.$i is online \033[0m" #加劇顏色顯示online else echo -e "\033[1;35m 192.168.51.$i is offline \033[0m" #同上 fi }& done wait echo "all Finished!" 再上一個python版本的 #!/usr/bin/python #Written By jerry #date 2018-03-20 import subprocess import threading def ping(host): result = subprocess.call( 'ping -c2 %s &> /dev/null' % host, shell=True ) if result == 0: print "%s:up" % host else: print "%s:down" % host if __name__ == '__main__': ips = ['192.168.12.%s' % i for i in range(1, 255)] for ip in ips: t = threading.Thread(target=ping, args=(ip,)) t.start()