2017年11月8日

網點測速


遇到一個問題,如何知道你的電腦的網路線是否有問題(網路是通的,下載速度慢),到底多慢?事實上網路速度有很多問題,從線、switch、ISP...。我們只能處理最基層問題(通常是校內),寫了一個shell來解決這想法。

從opensource.ntpc.edu.tw網站上,建一256MB的檔案,來當來源,如果自己能在校內主機放是最好。

再從自己的電腦下載這個檔案,用檔案大小/下載時間,可以得到一個大約數字,是你下載這個檔案的平均速度。

目前新北市各校間的連線速度是300MBt,如果你的下載速度能達到 10MB/秒以上,則網路速度應該是不錯的,如果只有不到1MB,則要報修了。


shell內容:

#!/bin/bash
path_d="163.20.174.98/netspeed/"
file_name="dd_256M"
cd /tmp
b_time=$(date +%s)
echo "自"$path_d"下載256MB檔案"
wget http://$path_d$file_name
e_time=$(date +%s)
echo "下載完成Download completed"
rm dd_256M

all_time=$(($e_time-$b_time))

netspeed=$(echo 256 $all_time | awk '{printf("%.2f", ($1/$2))}')
echo "下載時間(Download times):"$all_time"秒"
echo "平均下載速度(Download seed) :"$netspeed"MB/秒(MB/Second)"


shell下載:
https://drive.google.com/file/d/1prBsKdduzFUSDaeGiEbqY0rd2wFWOIYw/view?usp=sharing

有一個python程式還不錯用
安裝
apt-get install python-pip
pip install speedtest-cli

使用
列出測速主機
speedtest-cli --list
 太多了,找台灣主機,可以看到離你最近的主機(有寫出距離?km)
speedtest-cli --list |grep Taiwan
測速指令
speedtest-cli --server 2327
就可以看到上傳和下載速度了
speedtest-cli --server 2327
Retrieving speedtest.net configuration...
Testing from Digital United (112.104.30.26)...
Retrieving speedtest.net server list...
Selecting best server based on ping...
Hosted by Far Eastone Telecommunications Co., Ltd. (Taipei) [3.82 km]: 18.602 ms
Testing download speed................................................................................
Download: 89.78 Mbit/s
Testing upload speed................................................................................................
Upload: 1.38 Mbit/s