#********************************************************************
#scansubnet.sh # 脚本名
> /tmp/iplist.log #每次运行前清空该文件内容
read -p "Please input a netid:(eg:192.168.34.0) " netid #输入IP
netid=`echo $netid | sed -nr 's#(.*)\..*#\1#p'`
echo netid=$netid
for id in {1..254};do
{
if ping -c1 -w1 $netid.$id &>/dev/null ;then
echo "$netid.$id" >> /tmp/iplist.log #ping通的放入文件
echo $netid.$id is up
else
echo $netid.$id is down
fi
}& #并行执行
done
wait
保存完毕后bash scansubnet.sh 即可