How to Test Your Internet Speed Bidirectionally from Command Line Using ‘Speedtest-CLI’ Tool

We always need to check the speed of the Internet connection at home and office. What we do for this? Go to websites like Speedtest.net and begin test. It loads JavaScript in the web browser and then select best server based upon ping and output the result. It also uses a Flash player to produce graphical results.

What about headless server, where isn’t any web based browser and the main point is, most of the servers are headless. The another bottleneck of such web browser based speed testing is that, you can’t schedule the speed testing at regular interval. Here comes an application “Speedtest-cli” that removes such bottlenecks and let you test the speed of Internet connection from command line.

What is Speedtest-cli

The application is basically a script developed in Python programming Language. It measures Internet Bandwidth speed bidirectionally. It used speedtest.net infrastructure to measure the speed. Speedtest-cli is able to list server based upon physical distance, test against specific server, and gives you URL to share the result of your internet speed test.

To install latest speedtest-cli tool in Linux systems, you must have Python 2.4-3.4 or higher version installed on the system.

Install speedtest-cli in Linux

There are two ways to install speedtest-cli tool. The first method involves the use of python-pip package while the second method is to download the Python script, make it executable and run, here I will cover both ways….

Install speedtest-cli Using pythin-pip

First you need to install python-pip package, then afterwards you can install the speedtest-cli tool using pip command as shown below.

$ sudo apt-get install python-pip
$ sudo pip install speedtest-cli

To upgrade speedtest-cli, at later stage, use.

$ sudo pip install speedtest-cli --upgrade

Install speedtest-cli Using Python Script

First download the python script from github using wget command, unpack the downloaded file (master.zip) and extract it..

$ wget https://github.com/sivel/speedtest-cli/archive/master.zip
$ unzip master.zip 

After extracting the file, go to the extracted directory speedtest-cli-master and make the script file executable.

$ cd speedtest-cli-master/
$ chmod 755 speedtest_cli.py 

Next, move the executable to /usr/bin folder, so that you don’t need to type the full path everytime.

$ sudo mv speedtest_cli.py /usr/bin/

Testing Internet Connection Speed with speedtest-cli

1. To test Download and Upload speed of your internet connection, run the speedtest-cli command without any argument as shown below.

$ speedtest_cli.py
Test Download Upload Speed in Linux

Test Download Upload Speed in Linux

2. To check the speed result in bytes in place of bits.

$ speedtest_cli.py --bytes
Test Internet Speed in Bytes

Test Internet Speed in Bytes

3. Share your bandwidth speed with your friends or family. You are provided with a link that can be used to download an image.

# speedtest_cli.py --share
Share Internet Speed Results

Share Internet Speed Results

The following picture is a sample speed test result generated using above command.

Speed Test Results

Speed Test Results

4. Don’t need any additional information other than Ping, Download and upload?

$ speedtest_cli.py --simple
Test Ping Download Upload Speed

Test Ping Download Upload Speed

5. List the speedtest.net server based upon physical distance. The distance in km is mentioned.

$ speedtest_cli.py --list
Check Speedtest.net Servers

Check Speedtest.net Servers

6. The last stage generated a huge list of servers sorted on the basis of distance. How to get desired output? Say I only want to see the speedtest.net server located in Mumbai (India).

$ speedtest_cli.py --list | grep -i Mumbai
Check Nearest Server

Check Nearest Server

7. Test connection speed against a specific server. Use Server Id generated in example 5 and example 6 in above.

$ speedtest_cli.py --server [server ID]
$ speedtest_cli.py --server [5060]              ## Here server ID 5060 is used in the example.
Test Connection Against Server

Test Connection Against Server

8. To check the version number and help of speedtest-cli tool.

$ speedtest_cli.py --version
Check SpeedCli Version

Check SpeedCli Version

$ speedtest_cli.py --help
SpeedCli Help

SpeedCli Help

Note: Latency reported by tool is not its goal and one should not rely on it. The relative latency values output is responsible for server selected to be tested against. CPU and Memory capacity will influence the result to certain extent.

Conclusion

The tool is must for system administrators and developers. A simple script which runs without any issue. I must say that the application is wonderful, lightweight and do what it promises. I disliked Speedtest.net for the reason it was using flash, but speedtest-cli gave me a reason to love them.

speedtest_cli is a third party application and should not be used to automatically record the bandwidth speed. Speedtest.net is used by millions of users and it is a good idea to Set Your Own Speedtest Mini Server.

That’s all for now, till then stay tuned and connected to Tecmint. Don’t forget to give your valuable feedback in the comments below. Like and share us and help us get spread.

Best Affordable Linux and WordPress Services For Your Business
Outsource Your Linux and WordPress Project and Get it Promptly Completed Remotely and Delivered Online.

If You Appreciate What We Do Here On TecMint, You Should Consider:

  1. Stay Connected to: Twitter | Facebook | Google Plus
  2. Subscribe to our email updates: Sign Up Now
  3. Get your own self-hosted blog with a Free Domain at ($3.45/month).
  4. Become a Supporter - Make a contribution via PayPal
  5. Support us by purchasing our premium books in PDF format.
  6. Support us by taking our online Linux courses

We are thankful for your never ending support.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide

You may also like...

40 Responses

  1. crt says:

    This would be more useful if it could be used between two servers on the same internal network; between subnets and over VPN’s and not just “yet another internet speedtest” application.

  2. Kirk M says:

    I noticed that attempting to run:

    ‘speedtest_cli.py’

    …from the terminal after the two packages were installed using ‘apt’, the result was no command found running Linux Mint 18.1). It appears that the correct command is:

    ‘speedtest-cli’ (with a ‘dash’ not an ‘underscore’ and no ‘.py’ at the end)

    The above works fine although I tend to like to see the results in bytes not bits so I added –bytes at the end.

  3. Rob Philp says:

    You said it “should not be used to record internet speed automatically”. Why? I’d like to have this scheduled to run regularly and keep a log of my internet speeds to use when addressing poor service with my ISP.

  4. verow says:

    3. Share your bandwidth speed with your friends or family. You are provided with a link that can be used to download an image.
    in this section, missing the example of the command line :-)

    # speedtest_cli.py –share

    • Ravi Saive says:

      @Verow,

      Thanks for updating that missing command about sharing network bandwidth usage report, updated in the article..

  5. David Menges says:

    I don’t suppose this will install on Mac OS?

    • Abid says:

      Why do you say that? Mac OS is BSD under the covers. But, you will have to make sure Xcode is already installed first which is a free download from the Mac App store.

      Do this in a Terminal window after you have installed Xcode:

      1. Think of a location where you would want to keep the source files and “cd” into that directory, for example, I keep my sources in ~/src
      2. Download the code from GitHub:

      sudo git clone https://github.com/sivel/speedtest-cli.git

      The above may generate a message saying you have to agree to Xcode’s license agreement before being allowed to use Xcode.
      Type in “agree” when prompted.

      3. You will now have a directory titled speedtest-cli; cd into this directory
      4. Install the sources:

      sudo python ./setup.py install

      It should run without any warnings or errors (will get installed in /usr/local/bin).

      5. Now you can run the following for the help screen (usage info):

      speedtest-cli -h

  6. couldn’t install speedtest-cli in centOS 6.7 . Following error occured:

    yum install speedtest-cli
    Loaded plugins: fastestmirror, refresh-packagekit, security
    Setting up Install Process
    Loading mirror speeds from cached hostfile
    * base: mirror.tadu.vn
    * epel: http://ftp.cuhk.edu.hk
    * extras: mirror.tadu.vn
    * updates: mirror.nbrc.ac.in
    No package speedtest-cli available.
    Error: Nothing to do

    • Ravi Saive says:

      @Spandan,
      There isn’t any speedtest-cli package available from Yum repositories, the only way is to install it from PIP tool as described in this article. So, first install pip package and then do pip to install the speedtest-cli package as shown in this article..

  7. waldi says:

    CENTOS 6.6
    speedtest ver. 0.3.2
    Change line 343 in the script
    https
    to
    http
    Voilà :)

Leave a Reply to crt Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.