24 Feb 2018

How to test internet bandwidth with command line

There are multiple tools we could use to test the internet bandwidth at home. What if a server?

In China, PC users could install applications like tencent PC manager to test downloading and uploading speed. However, Mac users and Linux server administrators might want to know their bandwidth in specific scenes. If you have a screen and a web browser, just click GO on speedtest.org home page could be the easiest way. If you don’t, no worries, a command line tool speedtest-cli will help you.

3 ways to install

This tool which works with Python 2.4 ~ 3.7 could be installed on Windows, Mac OSX and Linux. What you need to do is using pip command,

pip install speedtest-cli

Or clone the whole project from Github,

git clone https://github.com/sivel/speedtest-cli.git
python speedtest-cli/setup.py install

If you haven’t install commands pip or git, the traditional installation way is effected as well.

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

start to test

Extremely easy. Input speedtest-cli into the terminal, speedtest-cli Actually the tool is so strong that you have these parameters to use,

$ speedtest-cli -h
usage: speedtest-cli [-h] [--no-download] [--no-upload] [--bytes] [--share]
                     [--simple] [--csv] [--csv-delimiter CSV_DELIMITER]
                     [--csv-header] [--json] [--list] [--server SERVER]
                     [--exclude EXCLUDE] [--mini MINI] [--source SOURCE]
                     [--timeout TIMEOUT] [--secure] [--no-pre-allocate]
                     [--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
  --no-download         Do not perform download test
  --no-upload           Do not perform upload test
  --bytes               Display values in bytes instead of bits. Does not
                        affect the image generated by --share, nor output from
                        --json or --csv
  --share               Generate and provide a URL to the speedtest.net share
                        results image, not displayed with --csv
  --simple              Suppress verbose output, only show basic information
  --csv                 Suppress verbose output, only show basic information
                        in CSV format. Speeds listed in bit/s and not affected
                        by --bytes
  --csv-delimiter CSV_DELIMITER
                        Single character delimiter to use in CSV output.
                        Default ","
  --csv-header          Print CSV headers
  --json                Suppress verbose output, only show basic information
                        in JSON format. Speeds listed in bit/s and not
                        affected by --bytes
  --list                Display a list of speedtest.net servers sorted by
                        distance
  --server SERVER       Specify a server ID to test against. Can be supplied
                        multiple times
  --exclude EXCLUDE     Exclude a server from selection. Can be supplied
                        multiple times
  --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
  --no-pre-allocate     Do not pre allocate upload data. Pre allocation is
                        enabled by default to improve upload performance. To
                        support systems with insufficient memory, use this
                        option to avoid a MemoryError
  --version             Show the version number and exit

For example, if you want to list all the test nodes in your country/region, try command like this,
(ignore the Ukraine one …) speedtest-cli_region Share(Show off) you bandwidth? Use –share, speedtest-cli_share Notice the URL? Visit it and you could get a graphical Internet bandwidth testing result like the cover shows, speedtest-cli_image

Python API

This tool also provides python APIs which might help you to aviod MemoryError, set a mini server or set Bind source. Read the wiki to learn how to use them.









ref: https://github.com/sivel/speedtest-cli