linux测试即时网速

平时在测试客户端网速时,linux上没有好的工具,只好自己写脚本来进行测试,以下是我平时实用的一个测试脚本工具,比较简单,仅供参考.

Cat bw_test.sh

#!/bin/bash
out()
{
exit
}

trap "out" 2

while true
do
string1=`ifconfig $1 | grep "bytes" | awk '{printf $2}'`
rx1=${string1##bytes:}
string2=`ifconfig $1 | grep "bytes" | awk '{printf $6}'`
tx1=${string2##bytes:}
sleep 1
clear
string3=`ifconfig $1 | grep "bytes" | awk '{printf $2}'`
rx2=${string3##bytes:}
string4=`ifconfig $1 | grep "bytes" | awk '{printf $6}'`
tx2=${string4##bytes:}
#echo $rx1
#echo $rx2
temp=`expr $rx2 - $rx1`
r1=`expr $temp / 1024`
echo 当前下载速度:$r1 kB/s
temp=`expr $tx2 - $tx1`
r2=`expr $temp / 1024`
echo 当前上传速度:$r2 KB/s
done