Skip to content

Instantly share code, notes, and snippets.

@stawidy
Last active December 26, 2018 03:25
Show Gist options
  • Save stawidy/6cdafb645c8b6090b4515ee45f4463c8 to your computer and use it in GitHub Desktop.
Save stawidy/6cdafb645c8b6090b4515ee45f4463c8 to your computer and use it in GitHub Desktop.
superspeed.sh without root
#!/usr/bin/env bash
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
SKYBLUE='\033[0;36m'
PLAIN='\033[0m'
# install speedtest
if [ ! -e '/tmp/speedtest.py' ]; then
wget --no-check-certificate -P /tmp https://raw.github.com/sivel/speedtest-cli/master/speedtest.py > /dev/null 2>&1
fi
chmod a+rx /tmp/speedtest.py
result() {
download=`cat /tmp/speed.log | awk -F ':' '/Download/{print $2}'`
upload=`cat /tmp/speed.log | awk -F ':' '/Upload/{print $2}'`
hostby=`cat /tmp/speed.log | awk -F ':' '/Hosted/{print $1}'`
latency=`cat /tmp/speed.log | awk -F ':' '/Hosted/{print $2}'`
clear
echo "$hostby"
echo "延迟 : $latency"
echo "上传 : $upload"
echo "下载 : $download"
echo -ne "\n当前时间: "
echo $(date +%Y-%m-%d" "%H:%M:%S)
}
speed_test(){
temp=$(python /tmp/speedtest.py --server $1 --share 2>&1)
is_down=$(echo "$temp" | grep 'Download')
if [[ ${is_down} ]]; then
local REDownload=$(echo "$temp" | awk -F ':' '/Download/{print $2}')
local reupload=$(echo "$temp" | awk -F ':' '/Upload/{print $2}')
local relatency=$(echo "$temp" | awk -F ':' '/Hosted/{print $2}')
temp=$(echo "$relatency" | awk -F '.' '{print $1}')
if [[ ${temp} -gt 1000 ]]; then
relatency=" 000.000 ms"
fi
local nodeName=$2
printf "${YELLOW}%-17s${GREEN}%-18s${RED}%-20s${SKYBLUE}%-12s${PLAIN}\n" "${nodeName}" "${reupload}" "${REDownload}" "${relatency}"
else
local cerror="ERROR"
fi
}
echo ""
printf "%-14s%-18s%-20s%-12s\n" "Node Name" "Upload Speed" "Download Speed" "Latency"
start=$(date +%s)
speed_test '12637' '襄阳电信'
speed_test '7509' '昆明电信'
speed_test '3633' '上海电信'
speed_test '19076' '重庆电信'
speed_test '3973' '兰州电信'
speed_test '5460' '哈尔滨联通'
speed_test '4863' '西安联通'
speed_test '5083' '上海联通'
speed_test '2461' '成都联通'
speed_test '4884' '福建联通'
speed_test '5292' '西安移动'
speed_test '4713' '北京移动'
speed_test '6715' '宁波移动'
speed_test '6168' '昆明移动'
speed_test '4515' '深圳移动'
end=$(date +%s)
rm -rf /tmp/speedtest.py
echo ""
time=$(( $end - $start ))
if [[ $time -gt 60 ]]; then
min=$(expr $time / 60)
sec=$(expr $time % 60)
echo -ne "花费时间:${min}${sec}"
else
echo -ne "花费时间:${time}"
fi
echo -ne "\n当前时间: "
echo $(date +%Y-%m-%d" "%H:%M:%S)
echo "测试完成!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment