When you are experiencing slow Internet access, you may want to test the Internet speed of your upstream ISP (often called “last mile” in the residential broadband networks) as part of troubleshooting. For that matter, Speedtest.net is probably the most widely used broadband speed testing website.
Underneath it, Speedtest.net loads JavaScript code in your web browser, which then automatically detects the closest Speedtest.net server from you, and measures download/upload speed by sending HTTP GET and POST requests to the server.
However, if you are trying to check Internet speed from a remote headless server, VPS or an otherwise desktop-less system, Speedtest.net’s Flash-based user-friendly interface would be no good. For those of you, there is a command-line interface (CLI) version of Speedtest.net, known as speedtest-cli. Here I will demonstrate how to use speedtest-cli to check Internet speed from the command line in Linux.
Install speedtest-cli on Linux
speedtest-cli is a simple CLI client written in Python for measuring bidirectional Internet bandwidth by using Speedtest.net infrastructure. It works with Python 2.4-3.4. Installing the latest speedtest-cli is nothing more than downloading the Python script.
$ wget https://raw.github.com/sivel/speedtest-cli/master/speedtest_cli.py $ chmod a+rx speedtest_cli.py $ sudo mv speedtest_cli.py /usr/local/bin/speedtest-cli $ sudo chown root:root /usr/local/bin/speedtest-cli
Test Internet Connection Speed with speedtest-cli
It is straightforward to check your Internet speed with speedtest-cli. Running speedtest-cli command without any argument gets its job done.
$ speedtest-cli
This will automatically discover the closest Speedtest.net server (in terms of geographic distance), and report download and upload speed measured from the server.
Retrieving speedtest.net configuration... Retrieving speedtest.net server list... Testing from China Telecom (61.164.214.73)... Selecting best server based on ping... Hosted by Xi'an branch,Chinaunicom (Xian) [365.99 km]: 74.307 ms Testing download speed........................................ Download: 5.84 Mbits/s Testing upload speed.................................................. Upload: 3.93 Mbits/s
If you want to share the speed test result, you can use “–share” option, which will allow you to share speed test result with others in an image format via Speedtest.net.
$ speedtest-cli --share Retrieving speedtest.net configuration... Retrieving speedtest.net server list... Testing from China Telecom (61.164.214.73)... Selecting best server based on ping... Hosted by Xi'an branch,Chinaunicom (Xian) [365.99 km]: 77.724 ms Testing download speed........................................ Download: 6.97 Mbits/s Testing upload speed.................................................. Upload: 4.04 Mbits/s Share results: http://www.speedtest.net/result/3598963488.png
If you want to get a list of available Speedtest.net servers around the world, use “–list” option. It will display a sorted list of Speedtest.net servers (geographically closest ones first).
$ speedtest-cli --list Retrieving speedtest.net configuration... Retrieving speedtest.net server list... 4690) China Unicom Lanzhou Branch Co.Ltd (Lanzhou, China) [158.10 km] 3973) China Telecom (Lanzhou, China) [158.10 km] 4504) China Mobile Group GanSu Co.Ltd (Lanzhou, China) [158.10 km] 4919) SECOM, Inc (Pueblo, CO, United States) [364.84 km] 4863) Xi'an branch,Chinaunicom (Xian, China) [365.99 km] 2461) China Unicom (Chengdu, China) [490.48 km] 4624) ChinaTelecom (Chengdu, China) [490.58 km] 4575) China Mobile Group Sichuan (Chengdu, China) [490.58 km] 4495) China Mobile Group Chongqing Co.,Ltd (Chongqing, China) [622.73 km] 4486) China Mobile Group Henan Co.,Ltd. (Zhengzhou, China) [789.19 km] 4595) China Telecom HeNan Branch (Zhengzhou, China) [789.19 km]
In the server list shown above, each Speedtest.net server shows an associated server ID in front. You can manually specify server ID during testing, instead of using the geographically closest server. For example, if I want to use a sever in Washington DC, I specify a corresponding server ID (e.g., 935).
$ speedtest-cli --server 935 Retrieving speedtest.net configuration... Retrieving speedtest.net server list... Testing from China Telecom (61.164.214.73)... Hosted by Speedtest.net (Washington, DC) [11795.66 km]: 91.235 ms Testing download speed........................................ Download: 0.49 Mbits/s Testing upload speed.................................................. Upload: 1.91 Mbits/s
NOTE: Don’t run any aggressive cron job! speedtest-cli is an unofficial third-party tool which is meant for residential users who want to check their broadband speed. You are NOT supposed to run any aggressive script with it. If you want to run automated bandwidth monitoring with speedtest-cli, you should set up your own Speedtest.net server with Speedtest Mini, and run any automated test against it, instead of bombarding the Speedtest.net’s infrastructure which is shared with many others!
Leave a Reply
You must be logged in to post a comment.