【www.bbyears.com--linux】
有时候自己在家里想找个ip给虚拟机做测试,但又不记得那些ip是在使用的,那些没有使用的(不要说你都记得,好吧,我承认我老了),所以写了个shell脚本来检测,方便自己使用.
脚本内容:
#!/bin/bash
# By rocdk890
#Check the network is online
read -p "Enter your network segment(example 192.168.1.):" ip_num
echo "Please wait..."
for i in `seq 1 254`
do
ping -c 2 -W 1 $ip_num$i >/dev/null
if [ $? -eq 0 ];then
echo "echo $ip_num$i is up"
echo $ip_num$i is up > ip_yes.txt
else
echo "echo $ip_num$i is down"
echo echo $ip_num$i is down > ip_no.txt
fi
done
exit 0
这个脚本方便大家输入自己网段来进行检测,不用去修改脚本.如下图
图中我只检测了10个ip.