How to use the command speedtest-cli (with examples)

How to use the command speedtest-cli (with examples)

Speedtest-cli is a command-line tool used to test internet bandwidth by connecting to speedtest.net servers. It provides precise details about download and upload speeds, latency, and server response times. The tool is highly versatile and offers various options to customize the test.

Use case 1: Run a speed test

Code:

speedtest-cli

Motivation: Running a basic speed test allows users to quickly assess their internet connection’s performance. This information is invaluable when troubleshooting network issues or comparing different service providers.

Explanation: The command speedtest-cli initiates the speed test. It connects to the closest available speedtest.net server and measures the download and upload speeds, as well as latency.

Example Output:

Retrieving speedtest.net configuration...
Testing from ISP (IP address: x.x.x.x)...
Retrieving speedtest.net server list...
Selecting best server based on latency...
Hosted by <Server Provider> [X.XX km]: 47.34 ms
Testing download speed........................................
Download: 50.14 Mbps
Testing upload speed..................................................
Upload: 25.20 Mbps

Use case 2: Run a speed test and display values in bytes, instead of bits

Code:

speedtest-cli --bytes

Motivation: By default, speedtest-cli provides download and upload speeds in bits per second (Mbps). However, displaying values in bytes per second (MB/s) may be more familiar to users or better align with their requirements.

Explanation: The --bytes option changes the display units from bits to bytes. This modification provides speed test results in a more commonly recognized format.

Example Output:

Retrieving speedtest.net configuration...
Testing from ISP (IP address: x.x.x.x)...
Retrieving speedtest.net server list...
Selecting best server based on latency...
Hosted by <Server Provider> [X.XX km]: 47.34 ms
Testing download speed........................................
Download: 6.27 MB/s
Testing upload speed..................................................
Upload: 3.15 MB/s

Use case 3: Run a speed test using HTTPS, instead of HTTP

Code:

speedtest-cli --secure

Motivation: Many users prefer the extra security provided by HTTPS, especially when transmitting sensitive data. Running the speed test over HTTPS ensures that the connection is encrypted and protected from potential eavesdroppers.

Explanation: The --secure option instructs speedtest-cli to use HTTPS for the speed test connection. This ensures the data transfer is encrypted.

Example Output:

Retrieving speedtest.net configuration...
Testing from ISP (IP address: x.x.x.x)...
Retrieving speedtest.net server list...
Selecting best server based on latency...
Hosted by <Server Provider> [X.XX km]: 47.34 ms
Testing download speed........................................
Download: 50.14 Mbps
Testing upload speed..................................................
Upload: 25.20 Mbps

Use case 4: Run a speed test without performing download tests

Code:

speedtest-cli --no-download

Motivation: In certain circumstances, users may only need information about their upload speed or want to exclude download tests for faster results. This use case allows users to focus on a specific aspect of their internet connection speed.

Explanation: The --no-download option skips the download speed test and only performs the upload test and latency measurement.

Example Output:

Retrieving speedtest.net configuration...
Testing from ISP (IP address: x.x.x.x)...
Retrieving speedtest.net server list...
Selecting best server based on latency...
Hosted by <Server Provider> [X.XX km]: 47.34 ms
Testing upload speed..................................................
Upload: 25.20 Mbps

Use case 5: Run a speed test and generate an image of the results

Code:

speedtest-cli --share

Motivation: Generating an image of the speed test results can facilitate sharing the information with others, such as network administrators or internet service providers. It provides a visual representation of the test outcome for easier analysis or communication.

Explanation: The --share option generates a unique URL that displays the speed test results as an image. The URL can be shared with others to provide access to the image.

Example Output:

Retrieving speedtest.net configuration...
Testing from ISP (IP address: x.x.x.x)...
Retrieving speedtest.net server list...
Selecting best server based on latency...
Hosted by <Server Provider> [X.XX km]: 47.34 ms
Testing download speed........................................
Download: 50.14 Mbps
Testing upload speed..................................................
Upload: 25.20 Mbps

Share results: <https://www.speedtest.net/result/image/xxxxxxxxxxx.png>

Use case 6: List all speedtest.net servers, sorted by distance

Code:

speedtest-cli --list

Motivation: Accessing a list of speedtest.net servers can be useful to see the existing options and determine the most suitable ones for a particular location. By sorting the servers by distance, users can identify the closest servers, usually resulting in more accurate test results.

Explanation: The --list option retrieves and lists all the speedtest.net servers. The servers are then sorted by distance, with the closest ones appearing first.

Example Output:

Retrieving speedtest.net configuration...
1) <Server Name 1>
   Server ID: xxxxxxx
   Distance: X.XX km

2) <Server Name 2>
   Server ID: xxxxxxx
   Distance: X.XX km

...

Use case 7: Run a speed test to a specific speedtest.net server

Code:

speedtest-cli --server server_id

Motivation: When troubleshooting network issues or comparing different speedtest.net servers, it can be beneficial to run speed tests to specific servers. This allows users to determine the performance of individual servers or compare results between them.

Explanation: The --server option specifies the speedtest.net server ID. Running the command with the server ID initiates the speed test to that specific server.

Example Output:

Retrieving server list...
Testing from ISP (IP address: x.x.x.x)...
Selecting server ID: xxxxxxx
Hosted by <Server Provider> [X.XX km]: 47.34 ms
Testing download speed........................................
Download: 50.14 Mbps
Testing upload speed..................................................
Upload: 25.20 Mbps

Use case 8: Run a speed test and display the results as JSON

Code:

speedtest-cli --json

Motivation: Getting the speed test results in a structured format like JSON can facilitate automating or integrating the information into other tools or systems. It allows for easier parsing and extracting specific data points programmatically.

Explanation: The --json option instructs speedtest-cli to return the speed test results in JSON format rather than the default human-readable format. This suppresses progress information during the test.

Example Output:

{
  "download": 50140000,
  "upload": 25200000,
  "ping": 47.34,
  "server": {
    "url": "<Server URL>",
    "lat": "X.XXXXXXXXXX",
    "lon": "X.XXXXXXXXXX",
    "name": "<Server Name>",
    "country": "United States",
    "cc": "US",
    "sponsor": "<Server Provider>",
    "id": "xxxxxxxxxx",
    "host": "<Server Host>",
    "d": X.XX,
    "latency": 47.34
  },
  ...
}

Conclusion:

Speedtest-cli is a powerful command-line tool for testing internet bandwidth using speedtest.net servers. It offers a wide range of options to customize the speed test and obtain results in different formats. Whether users need a quick analysis of their network performance or want to delve into more specific details, speedtest-cli provides the necessary flexibility and information.

Related Posts

How to use the command virt-manager (with examples)

How to use the command virt-manager (with examples)

The virt-manager command is a CLI launcher for virt-manager, which is a desktop user interface for managing KVM and Xen virtual machines and LXC containers.

Read More
dvc checkout (with examples)

dvc checkout (with examples)

1: Checkout the latest version of all target files and directories dvc checkout Motivation: The motivation behind using this command is to retrieve the latest version of all target files and directories from the DVC cache.

Read More
Using the doctl compute droplet command (with examples)

Using the doctl compute droplet command (with examples)

1: Creating a droplet To create a droplet using the “doctl compute droplet” command, you can use the following syntax:

Read More