Running a speed test can be very useful to verify the current state of an internet connection, for example, to verify that our ISP (Internet Service Provider) is respecting the parameters we are paying for, or to diagnose possible problems.
One of the most common ways to check ping, download and upload values is to run a test from the speedtest.net website. The
speedtest-cli program let us run the same test from our beloved command line interface.
In this tutorial you will learn:
- How to install and use the speedtest-cli application
- What are the most useful options we can use to modify its behavior
Software Requirements and Conventions Used
|Category||Requirements, Conventions or Software Version Used|
|Software||git and python|
|Other||No special requirements.|
|Conventions||# – requires given linux commands to be executed with root privileges either directly as a root user or by use of
$ – requires given linux commands to be executed as a regular non-privileged user
What is the speedtest-cli application?
Written in python, the
speedtest-cli utility, is basically the command line interface equivalent of running a speed test from the
speedtest.net website. The utility is completely open source, released under the
Apache 2.0 license. It can be really useful to check the efficiency of an internet connection when working in a command line environment, or when scripting. In this tutorial we will see how to use it and what are the most interesting options we can use to modify its behavior.
There are fundamentally three ways of installing the
speedtest-cli application. Since the program is present in the default repositories of all the major linux distributions, the first and preferred installation method is the one which involves the use of our favorite package manager. For example, to install the application on Fedora we use
$ sudo dnf install speedtest-cli
On Debian or Debian-based distributions we can use the good old
$ sudo apt-get update && sudo apt-get install speedtest-cli
Speedtest-cli is also present in the Archlinux’s
Community repository, therefore we can install it via
$ sudo pacman -S speedtest-cli
speedtest-cli is written in python, is also possible to install it in a distro-independent way, by using
pip (or pip3), the python package manager. When installing the package this way, I recommend the use of the
--user flag to perform the action only for our user:
$ pip3 install speedtest-cli --user
Finally, we can install
speedtest-cli by cloning the github repository:
$ git clone https://github.com/sivel/speedtest-cli
Once the repository is cloned we can switch inside of it and issue the following command:
$ python3 setup.py install --user
How to use speedtest-cli
The easiest way of using
speedtest-cli, is just by invoking it without options in the terminal. First the application will select the closest available server to test the connection against, then it will display the
We saw the basic usage of the command, now let’s see how we can customize its behavior with the possible options.
Sharing the results with the –share option
One very useful option of
--share: when using it, a graphical representation of the results of the speed test will be generated and hosted online; the command will return the URL we can use to access and share it:
Using the csv or json formats for the results
Speedtest-cli can generate the results in csv format by using the
--csv option. In this case the verbose output its suppressed and the results are generated on a single line using a
, (comma), as the default field delimiter. This can be changed by using the
--csv-header option. For example, to use the
| character as the delimiter, we can run:
$ speedtest-cli --csv --csv-delimiter '|'
The csv headers can be printed by using
$ speedtest-cli --csv-header Server ID,Sponsor,Server Name,Timestamp,Distance,Ping,Download,Upload
The results can also be represented by using the
json format. The
--json option can be used to obtain this behavior.
Test the connection against a specific server
As said above, by default, the program runs a test against the closest speedtest.net server. If we want to force the test against a specific server, we first have to generate the list of the available ones:
$ speedtest-cli --list [...] 22813) WebFi S.r.l. (Modugno, Italy) [315.52 km] 10456) Telecom Italia S.p.A. (Bari, Italy) [320.40 km] 2039) Irpinia Net-Com (Avellino, Italy) [321.58 km] 21306) Wirlab (Avellino, Italy) [321.58 km] 22718) WebFi S.r.l. (Molfetta, Italy) [327.15 km] 11114) NovaConn ISP (Nola, Italy) [333.23 km] 10405) Telecom Italia S.p.A. (Naples, Italy) [334.67 km] 19953) WARIAN (Napoli, Italy) [335.60 km] 17359) Vola (Pomigliano D'Arco, IT) [336.23 km] 15994) Lo Conte Wifi SRL (Ariano Irpino, Italy) [336.91 km] 20850) ALTITUD Internet Company (Barletta, Italy) [338.79 km] 11888) Nova Networks srl (Barletta, Italy) [338.79 km] 14772) AirLan Srl (Barletta, Italy) [339.12 km] 20618) Witecno Srl (Giugliano in Campania, Italy) [346.32 km] 7020) YouCall (Aversa, Italy) [349.48 km] 18695) WIBER (Caserta, Italy) [353.88 km] 15920) Interfibra (Campobasso, Italy) [391.48 km] 14706) Telecom Italia S.p.A. (Campobasso, Italy) [391.48 km] 9329) Dimensione Srl (Campobasso, Italy) [391.48 km] 5793) LinkWireless.IT (Minturno, Italy) [397.94 km] 7029) Ari@net Srl (Rotello, Italy) [403.58 km] 5981) LuvaGroup (Lushnje, Albania) [415.57 km] 15928) Velcom S.r.l.s (Terracina, Italy) [426.26 km] 2435) Albtelecom sh.a (Durres, Albania) [432.81 km] 17277) Connetta Srl (Sora, IT) [446.40 km] 19068) Seeweb (Frosinone, Italy) [450.42 km] 7769) SINET Srl (Scanno, Italy) [452.76 km] 14524) ABCom ltd (Tirana, Albania) [453.96 km] 1755) Vodafone AL (Tirana, Albania) [454.24 km] 1430) Albtelecom sh.a (Tirana, Albania) [454.24 km] 3108) ABCOM Shpk (Tirana, Albania) [454.24 km] 6045) Digicom AL sh.a (Tirana, Albania) [454.24 km] [...]
The list is quite long, therefore just a part of it is reported here. Now, to test the connection against a specific server, we run the command with the
--server option, providing the server ID (which is reported in the first column of the list) as the argument:
$ speedtest-cli --server 1430
In this tutorial we saw how to install and use the
speedtest-cli application. The program is basically the command line interface equivalent of running a speed test on the https://www.speedtest.net site, and can be very useful when operating on a machine without a graphical server installed.
We saw how it’s possible to obtain results in various formats like
csv and how to automatically share them. We also saw how to generate the list of all available servers used as endpoints, and how to manually pick one instead of using the automatic detection of the closest.