Internet speedtest from Linux command line

There are lots of online tools for checking your ISP provided internet speed. Most are web based interfaces and there are some great ones out there. The most popular is probably www.speedtest.net, but we also have www.fast.com, www.speedof.me, … even Google let’s you do it directly from its search page (you have to search using US-based google.com, not any of Google’s other country TLDs).

You can also do it from the Linux command line using a few open source tools. Here is how to do it…

(Note that all my speeds are low here since I’m downloading in the background!)


Speedtest.net

You can download the python script to run the speedtest.net Linux command line interface tool from here (obviously python is a pre-requisite):
https://github.com/sivel/speedtest-cli

You can install using git, pip/easy-install or download with wget. I’m going to use pip

pip install speedtest-cli

Typing speedtest-cli –help  shows you this output listing all available options:

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

I’ve found the best way to run this is to use the bytes option, and pick a server relatively local (you can find the available servers by running speedtest-cli –list , probably worth grepping to narrow it down to your country, speedtest-cli –list | grep “Great Britain” ):

speedtest-cli --bytes --server 3730

Returns:

Retrieving speedtest.net configuration...
Retrieving speedtest.net server list...
Testing from Moldtelecom (93.115.84.202)...
Hosted by Virgin Media (Edinburgh) [532.85 km]: 170.272 ms
Testing download speed........................................
Download: 1.92 Mbyte/s
Testing upload speed..................................................
Upload: 0.95 Mbyte/s

And comparing to the web interface we see:

Remember 1 megabyte per second = 8 megabits per second, and the web interface returns results in megabits per second.


speedtest.sh

If you don’t have python installed you can use the script below which is entirely written in bash. This could be useful for running on some internet-of-things devices which have telnet or SSH but don’t have python installed. Or to run on some routers (e.g. DD-WRT or Tomato) which you can SSH into but may not have python installed.

Download from http://dl.getipaddr.net/ or just run these commands to download and run once you’re in the folder you want to keep the script in:

wget https://raw.github.com/blackdotsh/curl-speedtest/master/speedtest.sh && chmod u+x speedtest.sh

bash speedtest.sh

Returns:

-------------Speed test--------------------
Testing North America locations
Speedtest from Portland, Oregon, USA [ generously donated by http://bonevm.com ] on a shared 100 Mbps port
Download Speed: .33 MB/sec
Upload speed: .62 MB/sec
Speedtest from Seattle, Washington, USA [ generously donated by http://ramnode.com ] on on a shared 1 Gbps port
Download Speed: 1.22 MB/sec
Upload speed: .95 MB/sec

This script will keep looping through different servers until you cancel it (Ctrl+C), at least I’ve never been patient enough to let it go long enough to finish on its own!

I’ve found that speedtest.sh tends to show much lower speeds than the other tools.


netspeed.sh

[Note netspeed.sh has now been depreciated (the author commented on this post below). You can find his new improved tool at https://git.io/speed instead.]

Or download and run with:

wget https://gist.githubusercontent.com/rsvp/1272488/raw/bf7ff5ed508b88c7e2030ea891b154c08f0690b5/netspeed.sh && chmod u+x netspeed.sh

bash netspeed.sh

Returns:

:: Rate in Kilobytes/sec; industry usually adopts megabits/sec:
:: 1 Kilobytes/sec (K/s) = 0.007813 megabits/sec (Mbps).
:: To CONVERT, use negated rate as first argument to netspeed.
:: [Terminate netspeed by control-C] [ cf. http://speedtest.net ]
::
--2016-08-23 22:16:08-- http://speedtest.fremont.linode.com/100MB-fremont.bin
Resolving speedtest.fremont.linode.com (speedtest.fremont.linode.com)... 50.116.14.9, 2600:3c01::4b
Connecting to speedtest.fremont.linode.com (speedtest.fremont.linode.com)|50.116.14.9|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 104857600 (100M) [application/octet-stream]
Saving to: ‘/dev/null’

100%[=====================================================================================================>] 104,857,600 904KB/s in 2m 18s

2016-08-23 22:18:27 (742 KB/s) - ‘/dev/null’ saved [104857600/104857600]


All credit to this Hak5 youtube video. They go into a lot more detail on this stuff in the video.

1 Comment

  1. Hi ! from the guy who wrote netspeed.sh …

    # SUMMARY

    The gist above, *netspeed.sh*, has been deprecated.

    ## Good news

    Work has shifted to using the infrastructure of speedtest.net and fast.com
    again made easily accessible by **Bash shell scripts** for all POSIX and Linux systems.
    Please visit https://git.io/speed to obtain the code. PR are welcomed!

Leave a Reply

(email optional)


Warning: Undefined array key "rerror" in /home/public/blog/wp-content/plugins/wp-recaptcha/recaptcha.php on line 291