#!/bin/bash
IP_HEAD='192.168.1.'
> ans.txt
ts=0
for i in {1..254}
do
{
ip=IP_HEADi
#echo ip
n=`ping -i 0.01 -c 3ip | grep 'trans' | grep -oP '\d*\s(?=rece)'`
echo nip >> ans.txt
}&
done
i=0
while true
do
sleep 1
let i++
# 最多执行100秒
if (( i>=100)); then
break;
fi
n=`cat ans.txt | wc -l`
echo "i: 完成n 条, 共计 254 条"
if (( n == 254 )); then
break;
fi
done
echo -e "--- \nping 同的地址有"
cat ans.txt | grep -oP '(?<=[1-9]\s).*' | sort -n -k 4 -t .