标签:编辑 inux bin strong host 主机 lin .sh txt
方法一:写一个shell脚本,循环ping网段内的每一个ip编辑并保存getAllHosts.sh脚本,内容是:
#!/bin/bash
NETWORK=$1
for HOST in $(seq 1 254)
do
ping -c 1 -w 1 $NETWORK.$HOST &>/dev/null && result=0 || result=1
if [ "$result" == 0 ];then
echo -e "\033[32;1m$NETWORK.$HOST is up! \033[0m"
#echo "$NETWORK.$HOST" >> /home/y/AllHosts_up.txt
else
echo -e "\033[;31m$NETWORK.$HOST is down!\033[0m"
#echo "$NETWORK.$HOST" >> /home/y/AllHosts_down.txt
fi
done
标签:编辑 inux bin strong host 主机 lin .sh txt
原文地址:https://blog.51cto.com/14055961/2386881