SpeedTest-CLI : A simple script to test internet speed from Linux Command line

Whenever you are experiencing slow Internet speed in home or office, you may want to test the Internet speed to know the status.

There are many online sites are available to check the Internet Bandwidth Speed.Those websites are bit heavy and having lots of annoying ads.

It loads JavaScript code in your web browser, then automatically detects the nearest server for you and finally measures download/upload speed by sending HTTP GET and POST requests to the server.

You can go with browser based testing, when you have a GUI and you have to look for alternative if you have a headless server.

speedtest.py is a simple python script which help us to test internet bandwidth (Upload & Download) speed in Linux command line using speedtest.net. It’s using pure socket tests instead of HTTP based tests.

Users can install speedtest-cli in six simple ways.

Install prerequisites

Make sure your system should have below prerequisite packages. If not, install before proceeding speedtest-cli installation.

For Debian users, use APT Package Manager or Apt-Get Package Manager to install Audit package.

$ sudo apt-get install python-pip git

For openSUSE users, use Zypper Package Manager to install Audit package.

$ sudo zypper install python-pip git

For Fedora users, use dnf Package Manager to install Audit package.

$ sudo dnf install python-pip git

For Arch Linux users, use pacman Package Manager to install Audit package.

$ sudo pacman -S python-pip git

For CentOS/RHEL user, use yum Package Manager to install Audit package.

$ sudo yum install python-pip git

Method-1 : Using pip

pip is a python module bundled with setuptools, it’s one of the recommended tool for installing Python packages in Linux. pip released later in 2008, as alternative to easy_install.

$ sudo pip install speedtest-cli
$ speedtest-cli

Method-2 : Using easy_install

Easy Install is a python module (easy_install) bundled with setuptools that lets you automatically download, build, install, and manage Python packages. easy_install was released in 2004, as part of setuptools.

$ sudo easy_install speedtest-cli
$ speedtest-cli

Method-3 : Using Github

Use the following command to install speedtest-cli using github.

$ sudo pip install git+https://github.com/sivel/speedtest-cli.git
$ speedtest-cli

Method-4 : Using Wget and cURL Command

Use wget or curl command to download the speedtest.py file and grand executable permission to run the speedtest-cli.

Using Wget command.

$ wget -O speedtest-cli https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py
$ chmod +x speedtest-cli
$ python speedtest-cli

Using cURL command.

$ curl -Lo speedtest-cli https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py
$ chmod +x speedtest-cli
$ python speedtest-cli

Method-5 : Using Git Clone

Just clone a repository from developer github page and navigate to speedtest-cli folder then run the speedtest.py file to avail the service.

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

Method-6 : Using Distribution Package

Use the distribution package manager to install speedtest-cli.

For Debian users, use APT Package Manager or Apt-Get Package Manager to install speedtest-cli package.

$ sudo apt-get install speedtest-cli

For Fedora users, use dnf Package Manager to install speedtest-cli package.

$ sudo dnf install python3-speedtest-cli

For Arch Linux users, use pacman Package Manager to install speedtest-cli package.

$ sudo pacman -S speedtest-cli

How to use speedtest-cli

I have added possible examples below to make you understand in better way. Simply run speedtest-cli command without any argument to test Download and Upload speed of your internet connection.

$ speedtest-cli
Retrieving speedtest.net configuration...
Testing from BBNL (103.5.134.167)...
Retrieving speedtest.net server list...
Selecting best server based on ping...
Hosted by E-Infrastructure & Entertainment India Pvt. Ltd (Bangalore) [16.80 km]: 8.468 ms
Testing download speed................................................................................
Download: 10.19 Mbit/s
Testing upload speed................................................................................................
Upload: 10.36 Mbit/s

Check result in Bytes

Run the speedtest-cli command with --bytes option to test Download and Upload speed in bytes insteadof bits.

$ speedtest-cli --bytes
Retrieving speedtest.net configuration...
Testing from BBNL (103.5.134.167)...
Retrieving speedtest.net server list...
Selecting best server based on ping...
Hosted by E-Infrastructure & Entertainment India Pvt. Ltd (Bangalore) [16.80 km]: 7.563 ms
Testing download speed................................................................................
Download: 1.28 Mbyte/s
Testing upload speed................................................................................................
Upload: 1.29 Mbyte/s

Generate a PNG output

Run the speedtest-cli command with --share option to generate a PNG output which will help us to share the test Download and Upload speed results to anyone through link.

$ speedtest-cli --share
Retrieving speedtest.net configuration...
Testing from BBNL (103.5.134.167)...
Retrieving speedtest.net server list...
Selecting best server based on ping...
Hosted by E-Infrastructure & Entertainment India Pvt. Ltd (Bangalore) [16.80 km]: 10.078 ms
Testing download speed................................................................................
Download: 10.22 Mbit/s
Testing upload speed................................................................................................
Upload: 7.11 Mbit/s
Share results: http://www.speedtest.net/result/6427222784.png

Print only Ping, Download & Upload info

Run the speedtest-cli command with --simple option to print only Ping, Download & Upload results instead of detailed output.

$ speedtest-cli --simple
Ping: 8.384 ms
Download: 10.07 Mbit/s
Upload: 10.31 Mbit/s

List the speedtest.net servers

List the speedtest.net servers based on geographical location.

$ speedtest-cli --list
Retrieving speedtest.net configuration...
 2564) Bharti Airtel Ltd (Bangalore, India) [16.80 km]
 7379) ACT Fibernet (Bangalore, India) [16.80 km]
 7971) E-Infrastructure & Entertainment India Pvt. Ltd (Bangalore, India) [16.80 km]
 6432) YOU Broadband India Pvt Ltd. (Bangalore, India) [16.80 km]
 4663) Hathway Cable & Datacom Ltd (Bangalore, India) [16.80 km]
 4706) Bell Teleservices Private Limited (Bangalore, India) [16.80 km]
10204) Spectranet (Bangalore, India) [16.80 km]
 5812) BSNL (Bangalore, India) [16.80 km]
11468) TTN Broadband (Bangalore, India) [16.80 km]
 7784) BBNL (Bangalore, India) [16.80 km]
 9282) In2cable (Bangalore, India) [16.80 km]
11014) SHERIE PLEXUS ISP PRIVATE LIMITED (Bangalore, India) [16.80 km]
12973) airwir technologies pvt ltd (Bangalore, India) [16.80 km]
 8448) LANCE FIBER NET PRIVATE LIMITED (Bangalore, India) [16.80 km]
 6756) ANT DATA LABS (Bangalore, India) [16.80 km]
 9966) Allnet Broadband Network Pvt Ltd (Bangalore, India) [16.80 km]
 9548) Sri Krishna Enterprises (Bidadi, India) [16.80 km]
12227) 10G Broadband (Bangalore, India) [16.80 km]
 9388) City Online Services Limited (Bangalore, India) [16.80 km]
12076) Assistive Networks and Technologies (Whitefield, India) [34.91 km]
11214) AirFiber Networks Pvt Ltd (Hosur, India) [51.26 km]
10503) Smart Wi5 Pvt. Ltd., (Hosur, India) [51.26 km]
 7869) North East Dataa Network Pvt Ltd (Mysore, India) [114.23 km]
 7867) ANT DATA LABS (Mysore, India) [114.23 km]
.
.

Test speed using server ID

Note down the speedtest.net server ID from the above output and run the following command to get a results.

$ speedtest_cli --server [server ID]

$ speedtest --server 6432
Retrieving speedtest.net configuration...
Testing from BBNL (103.5.134.167)...
Retrieving speedtest.net server list...
Selecting best server based on ping...
Hosted by YOU Broadband India Pvt Ltd. (Bangalore) [16.80 km]: 26.357 ms
Testing download speed................................................................................
Download: 9.83 Mbit/s
Testing upload speed................................................................................................
Upload: 10.38 Mbit/s

Read More

Navigate to speedtest-cli help page to know more options.

$ speedtest-cli --help

About Magesh Maruthamuthu

Love to play with all Linux distribution

View all posts by Magesh Maruthamuthu

Leave a Reply

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