获取IP端口延时 - 弃
貌似linux系统下tcping无法获取到端口延时的
使用方法
# sh u.sh 122.225.67.30 80 122.225.67.30:80 :测试5次,平均延时 28.0 ms # sh u.sh www.baidu.com 80 www.baidu.com:80 :测试5次,平均延时 6.9 ms
# @Author: richardzgt
# @Date: 2018-09-20 15:27:05
# @Last Modified by: 高涛
# @Last Modified time: 2019-01-17 16:05:42
if [ $# != 2 ]
then
echo "Wrong number of arguments eg: $0 ip port"
exit
fi
if [ ! -x /bin/traceroute ]; then
echo "Install traceroute first"
exit 3;
fi
IP=$1
PORT=$2
CNT=5
is_ok=0
declare -a all_ms
while true
do
for i in $(seq $CNT)
do
tr=$(/bin/traceroute -n -T -f 255 -m 255 -q 1 -w 3 -p $PORT $IP 2>&1| tail -n1 | sed 's/ / /g')
if ! echo "$tr" | grep 'ms$' > /dev/null
then
echo -n "."
else
ms=$(echo "$tr" | cut -d" " -f3)
all_ms=(${all_ms[*]} $ms)
is_ok=1
fi
done
if [ $is_ok -eq 1 ]; then
avg=`echo ${all_ms[*]}|awk '{n=split($0,b);for(i in b){sum+=b[i];count+=1}}END{printf "%0.1f",sum/count}'`
echo "${IP}:${PORT} :测试${CNT}次,平均延时 ${avg} ms"
else
echo "${IP}:${PORT} :测试失败"
fi
sleep 3
done

浙公网安备 33010602011771号