speedtest_cli speedtest Print

  • speedtest
  • 0

What is speedtest-cli?

Speedtest-cli is a script written in the Python programming language which measures the internet speed bidirectionally. This application allows you to check your internet speed upon distance in km, it can test against specific servers and it also provides a URL so that you can share your result on the internet.

How to install speedtest-cli on Linux?

Speedtest-cli can be run as a cronjob to get an internet speed test log. Open the crontab with this command:

apt-get install speedtest-cli

How to test internet connection speed with speedtest-cli?

Run the speedtest-cli command to test the download and upload speed of your internet connection without any argument:

speedtest-cli
Testing download speed........................................
Download: 916.39 Mbit/s
Testing upload speed..................................................
Upload: 489.57 Mbit/s

If you want to check the speed result in bytes instead of bits, then use this command:

speedtest-cli --bytes
Testing download speed........................................
Download: 114.15 Mbyte/s
Testing upload speed..................................................
Upload: 49.61 Mbyte/s

If you want to share the speed result with your friends, then you can download the image of the result with URL provided after the result.

speedtest-cli --share
Retrieving speedtest.net configuration...
Testing from Hetzner Online GmbH (..........)...
Retrieving speedtest.net server list...
Selecting best server based on ping...
Hosted by avrx (Limburg an der Lahn) [140.88 km]: 14.379 ms
Testing download speed................................................................................
Download: 309.68 Mbit/s
Testing upload speed................................................................................................
Upload: 316.33 Mbit/s
Share results: http://www.speedtest.net/result/xxxxxxxxxxx.png

Below is the picture of my speed test result from the test above.

Speedtest result.

If you want information only on ping, download and upload then use:

speedtest-cli --simple
Ping: 5.23 ms
Download: 877.56 Mbit/s
Upload: 162.21 Mbit/s

You can also check the list of server based upon the distance in km by using:

speedtest-cli --list
2628) Telstra (Adelaide, Australia) [17098.98 km]
4051) Vodafone Hutchison Australia (AE) (Adelaide, Australia) [17098.98 km]
...........................................................................
3254) Vodafone Hutchison Australia (PH) (Perth, Australia) [18700.26 km]
1931) IX Australia (Perth, Australia) [18700.26 km]

List of Speedtest servers.

By searching the list in terms of distance, you might have generated a big list of the servers. If you want to check the result for servers of a specific area, then you can check that by piping the result to the grep command (Australia is an example of the area):

speedtest-cli --list | grep –i Australia
2604) Telstra (Brisbane, Australia) [15501.92 km]
1594) 'Yes' Optus (Brisbane, Australia) [15501.92 km]
...............................................................................................
3254) Vodafone Hutchison Australia (PH) (Perth, Australia) [18700.26 km]
1931) IX Australia (Perth, Australia) [18700.26 km]

Speedtest results for Australia.

To test the connection speed against a specific server, you have to use the server ID generated in step 5 and 6.

speedtest-cli --server [server ID]
speedtest-cli --server 2604

Here server ID 2604 is used as an example:

Hosted by Telstra (Brisbane) [15501.92 km]: 452.614 ms
Testing download speed........................................
Download: 28.79 Mbit/s
Testing upload speed..................................................
Upload: 11.71 Mbit/s

If you want to check the help and version number of the speedtest-cli tool, use these commands:

speedtest-cli --version
0.3.4
speedtest-cli --help
usage: speedtest_cli [-h] [--bytes] [--share] [--simple] [--list]
[--server SERVER] [--mini MINI] [--source SOURCE]
[--timeout TIMEOUT] [--secure] [--version]
Command line interface for testing internet bandwidth using speedtest.net.
--------------------------------------------------------------------------
https://github.com/sivel/speedtest-cli
optional arguments:
-h, --help show this help message and exit
--bytes Display values in bytes instead of bits. Does not affect
the image generated by --share
--share Generate and provide a URL to the speedtest.net share
results image
--simple Suppress verbose output, only show basic information
--list Display a list of speedtest.net servers sorted by
distance
--server SERVER Specify a server ID to test against
--mini MINI URL of the Speedtest Mini server
--source SOURCE Source IP address to bind to
--timeout TIMEOUT HTTP timeout in seconds. Default 10
--secure Use HTTPS instead of HTTP when communicating with
speedtest.net operated servers
--version Show the version number and exit

Creating an internet speed log with speedtest-cli

Speedtest-cli can be run as a cronjob to get an internet speed test log. Open the crontab with this command:

crontab -e

And add this line (I'll assume that speedtest_cli.py is installed in /usr/local/bin) to the crontab:

30 00 * * *  /usr/local/bin/speedtest-cli >> /tmp/speedlog.txt

Save the changes and exit the crontab editor. This will run a speed test at 0:30 each day and appends the result to the file /tmp/speedlog.txt.


Was dit antwoord nuttig?

« Terug