shell习题-找出活动ip


写一个shell脚本,把192.168.0.0/24网段在线的ip列出来。
思路: for循环, 0.1 —  0.254  依次去ping,能通说明在线。

 

参考答案:

#!/bin/bash

ips="192.168.1."
for i in `seq 1 254`
do

ping -c 2 $ips$i >/dev/null 2>/dev/null
if [ $? == 0 ]
then
    echo "echo $ips$i is online"
else
    echo "echo $ips$i is not online"
fi
done