Believe it or not, there is a way to use Speedtest.net’s speed test service from a Linux command line. Usually, one would fire up a web browser and just go to Speedtest.net and the flash utility would load. Obviously, this is impossible from a command line. If you have a cloud instance or virtual private server (VPS), you don’t have a gui or a web browser. So, here is how to run an Internet speed test from the Linux command line.
To achieve this, there is a package called speedtest-cli. It is a python based utility that more or less has the same functionality as the gui. When ran with defaults, it will locate the closest server and run a download test, then an upload test, and display the results when it’s finished. You can do this by running:
# wget -O - https://raw.github.com/sivel/speedtest-cli/master/speedtest_cli.py | python
After the script downloads and runs, you’ll see something like this:
Retrieving speedtest.net configuration... Retrieving speedtest.net server list... Testing from AT&T U-verse (184.108.40.206)... Selecting best server based on latency... Hosted by TekLinks (Birmingham, AL) [103.61 km]: 30.383 ms Testing download speed........................................ Download: 98.96 Mbit/s Testing upload speed.................................................. Upload: 56.06 Mbit/s
Personally, I like to select a specific server from a specific location when I run a speed test. I’ve found that the closest server, isn’t always the fastest. Just because a speed test server is located a couple hundred miles from you, it does not mean the path to it is linear, and it doesn’t mean their connection is fast enough to saturate your own. Not to worry, you can also select a server to your liking. There are two ways to approach this. You can either install the speedtest-cli package using your package manager, or you can download the script manually. I’ll cover both.
To install the speedtest-cli package on Ubuntu
# sudo apt-get install speedtest-cli
After installing the package, you can simply run:
Now, if you’re using a distribution other than Ubuntu, or do not wish to install the package, you can simply download the script. To do that, do the following:
# wget https://raw.github.com/sivel/speedtest-cli/master/speedtest_cli.py # chmod +x speedtest_cli.py
The chmod command gives execute permission to the file. This is required to run it. Once you have downloaded the script, you can run it by doing this:
There are quite a few options you can use with the script. I’ll go over the few that I have used. First up is –share. This option gives you a web link to share you speed test results with others. You’ve probably seen the little png boxes before. They look like this:
So to get a nice automatically generated results picture like this, just run this command:
# ./speedtest_cli.py --share or # speedtest-cli --share
It will run the speed test like normal, but the very last line will have a link to your results. Now, like I was saying earlier, I like to specify the server the speed test runs against. To do that you first need to know the ID of the server you want to use. To get a list of speed test servers available, and their ID, run this command:
# ./speedtest_cli.py --list | more or # speedtest-cli --list | more
My favorite servers ID is 3595, so I’ll use it in my example. Once you have the ID of the server you want to use, all you need to do is specify it with the –server option. Be sure to swap out 3595 with the ID of your prefered server. Like this:
# ./speedtest_cli.py --server 3595 or # speedtest-cli --server 3595
There are some other pretty cool options available if you want to play around some more. You can display values in Bytes instead of Bits, use the URL of a Speedtest Mini server, and even select the source IP you want to bind to. If you want to check out the other options available, run this command.
# ./speedtest_cli.py --help or # speedtest-cli --help
That’s all there is to it. If you run into any troubles feel free to ask for help in the comments below. Thanks!