使用curl測試連接某網站的速度
curl指令本身有測速功能,搭配shell可以作為測速使用
curl -o /dev/null -s -w "%{time_namelookup},%{time_connect}, \
%{time_starttransfer},%{time_total}" \
https://tw.yahoo.com && echo
#------------產生數字--------------------
0.004188,0.060702, 1.931382,8.039616
0.004188 => DNS解析速度
0.060702 =>Client -> Sever(TCP request)
1.931382 => Server->Client(TCP Response)
8.039616 => 連線總共花費時間
了解規則後,就可以寫一個簡單的連線某網站的測速程式工具
$1表示第一個參數,使用到條件式 if.... else.... fi
vi curlweb-speed.sh
#!/bin/bash
if [ $1 ]; then
url=$1
else
echo "請輸入url(exp:tw.yahoo.com)"
read url
fi
curl -o /dev/null -s -w \
"DNS 解析: %{time_namelookup}\n\
Client Request: %{time_connect}\n\
Server Respon: %{time_starttransfer}\n\
總花費時間: %{time_total}\n" \
"${url}"

Last updated
Was this helpful?