Speedtest CLI: Test Your Internet Speed From Command Line

by Jhon Lennon 58 views

Hey guys! Ever been in a situation where you needed to quickly check your internet speed but didn't want to open a browser and navigate to a website? Well, you're in luck! The Speedtest CLI is here to save the day. It's a command-line interface for the popular Speedtest.net service, allowing you to test your internet speed directly from your terminal. This is super handy for developers, network admins, or anyone who just loves the command line. Let's dive into what it is, how to install it, and how to use it like a pro.

What is Speedtest CLI?

So, what exactly is Speedtest CLI? Simply put, it's the command-line version of the well-known Speedtest.net service. Instead of opening your web browser and going to the Speedtest website, you can run a simple command in your terminal to get your internet speed results. This tool measures your internet connection's download speed, upload speed, ping, and jitter. It provides a quick and efficient way to assess your network performance without the need for a graphical interface. One of the coolest things about using Speedtest CLI is its lightweight nature and speed. It doesn't hog resources like a browser-based test might, and it often provides results faster. Plus, it's scriptable! You can incorporate it into your scripts to automate speed tests and monitor your network performance over time. Imagine setting up a cron job to run a speed test every hour and log the results. This is especially useful for diagnosing intermittent connection issues. For network administrators, the Speedtest CLI is a godsend for remote server speed checks. You can quickly assess a server's connection speed without needing to log into a graphical interface. It's also perfect for testing connections on headless systems or devices without a web browser. Whether you're troubleshooting network issues, monitoring performance, or just curious about your internet speed, the Speedtest CLI is a versatile and powerful tool to have in your arsenal. It brings the reliability and accuracy of Speedtest.net to your command line, making it an essential utility for anyone working with networks.

Installation

Alright, let's get this show on the road and install Speedtest CLI! The installation process is straightforward and varies slightly depending on your operating system. Here’s a breakdown for different platforms:

macOS

If you're on macOS, the easiest way to install Speedtest CLI is through Homebrew. If you don't have Homebrew installed, you can get it from brew.sh. Once Homebrew is ready, open your terminal and run:

brew install speedtest-cli

This command tells Homebrew to download and install the Speedtest CLI package. After the installation is complete, you can verify it by running speedtest in your terminal. If it's installed correctly, you'll see the Speedtest CLI interface.

Linux

For Linux users, there are a couple of ways to install Speedtest CLI. One common method is to use apt on Debian-based systems (like Ubuntu) or yum on Red Hat-based systems (like Fedora).

Debian/Ubuntu:

First, update your package list:

sudo apt update

Then, install Speedtest CLI:

sudo apt install speedtest-cli

Red Hat/Fedora:

sudo yum install speedtest-cli

Alternatively, you can download the Speedtest CLI binary from the official Speedtest website and make it executable. Here’s how:

wget -O speedtest https://install.speedtest.net/app/cli/ookla-speedtest-1.1.1-linux-x86_64.tgz
tar xzf ookla-speedtest-1.1.1-linux-x86_64.tgz
sudo mv speedtest /usr/local/bin/
sudo chmod +x /usr/local/bin/speedtest

This downloads the binary, extracts it, moves it to /usr/local/bin/, and makes it executable.

Windows

For Windows users, the installation process is a bit different. You can download the Windows binary from the official Speedtest website. Once downloaded, extract the contents of the ZIP file to a directory of your choice, such as C:\Speedtest. Next, you'll want to add this directory to your system's PATH environment variable. This allows you to run the speedtest command from any command prompt window.

Here’s how to add it to your PATH:

  1. Open the Start Menu and search for “environment variables”.
  2. Select “Edit the system environment variables”.
  3. Click on “Environment Variables…”.
  4. In the “System variables” section, find the “Path” variable and click “Edit…”.
  5. Click “New” and add the path to your Speedtest CLI directory (e.g., C:\Speedtest).
  6. Click “OK” on all windows to save the changes.

After this, open a new command prompt window and type speedtest. If everything is set up correctly, you should see the Speedtest CLI interface.

Basic Usage

Now that you've got Speedtest CLI installed, let's talk about how to use it! The most basic command to run a speed test is simply:

speedtest

This command will run a standard speed test and display the results in your terminal. The output includes your download speed, upload speed, ping, and jitter. But Speedtest CLI is more than just a one-trick pony. It has a bunch of options that let you customize your speed tests. For example, if you want to see a more detailed output, you can use the --verbose option:

speedtest --verbose

This will give you a more in-depth look at the test process and additional information about your connection. Another useful option is --server, which allows you to specify a specific Speedtest server to use. This can be helpful if you want to test your connection to a particular server or if you're experiencing issues with the default server. To use this option, you need to know the server ID. You can find a list of server IDs by running:

speedtest --list

This will display a list of available Speedtest servers along with their IDs. Once you have the server ID, you can run a speed test against that server using the --server option:

speedtest --server 1234

Replace 1234 with the actual server ID. Speedtest CLI also supports saving the results to a file. This can be useful for tracking your network performance over time or for sharing your results with others. To save the results to a file, use the --output option:

speedtest --output results.txt

This will save the results of the speed test to a file named results.txt. You can then open this file to view the results. By mastering these basic commands and options, you'll be able to get the most out of Speedtest CLI and effectively monitor your internet connection.

Advanced Options

Alright, let's crank things up a notch and explore some of the advanced options that Speedtest CLI offers! These options allow you to fine-tune your speed tests and get even more detailed information about your network performance. One super useful option is --accept-license, which automatically accepts the Speedtest license agreement. This is particularly handy when you're running Speedtest CLI in scripts or automated environments where you can't manually accept the license. Here's how you use it:

speedtest --accept-license

Another cool option is --progress, which displays real-time progress updates during the speed test. This can be helpful if you want to see what's happening behind the scenes and monitor the progress of the test. To use it, just add --progress to your command:

speedtest --progress

If you're concerned about privacy, you can use the --privacy option to hide your IP address from the Speedtest results. This can be useful if you're sharing your results with others and don't want to reveal your IP address. To use this option:

speedtest --privacy

Speedtest CLI also supports specifying the interface to use for the speed test. This can be useful if you have multiple network interfaces and want to test a specific one. To specify the interface, use the --interface option followed by the name of the interface:

speedtest --interface eth0

Replace eth0 with the actual name of your network interface. For those who want to delve deeper into the technical aspects of their connection, the --bytes option displays the results in bytes instead of bits. This can be useful for more precise measurements. To use it:

speedtest --bytes

Finally, if you want to get the raw JSON output of the speed test results, you can use the --json option. This is perfect for integrating Speedtest CLI with other tools and scripts that require structured data:

speedtest --json

By mastering these advanced options, you can tailor Speedtest CLI to your specific needs and gain a deeper understanding of your network performance. Whether you're automating speed tests, troubleshooting network issues, or just curious about your connection, these options will help you get the most out of Speedtest CLI.

Examples and Use Cases

Let's explore some real-world examples and use cases where Speedtest CLI can be a game-changer! Imagine you're a network administrator troubleshooting slow internet speeds on a server. Instead of relying on GUI-based tools, you can quickly run Speedtest CLI to diagnose the issue. Here's how you might do it:

ssh user@server 'speedtest --accept-license --server 1234 --verbose'

This command connects to the server via SSH and runs a speed test against a specific server (1234), accepting the license agreement and providing verbose output. The results are displayed directly in your terminal, allowing you to quickly assess the server's connection speed. Another common use case is monitoring network performance over time. You can create a script that runs Speedtest CLI at regular intervals and logs the results to a file. This can help you identify trends and detect potential issues before they become major problems. Here's an example script:

#!/bin/bash

DATE=$(date +"%Y-%m-%d %H:%M:%S")
RESULTS=$(speedtest --accept-license --json)

echo "$DATE - $RESULTS" >> speedtest_log.txt

This script runs Speedtest CLI, formats the output as JSON, and appends it to a log file along with the current date and time. You can then set up a cron job to run this script every hour or every day. Developers can also use Speedtest CLI to test the performance of their applications. For example, if you're building a web application that relies on fast internet speeds, you can use Speedtest CLI to verify that your users have a sufficient connection. Here's how you might integrate Speedtest CLI into your testing workflow:

if speedtest --accept-license --download < 10;
then
 echo "Internet speed is too slow!
 exit 1
fi

This script checks if the download speed is less than 10 Mbps. If it is, it prints an error message and exits. This can help you ensure that your application performs well even on slower connections. Speedtest CLI is also invaluable for remote workers who need to verify their internet speed. You can quickly run a speed test from your command line to ensure that your connection meets the requirements for video conferencing, file sharing, and other online activities. By leveraging these examples and use cases, you can see how Speedtest CLI can be a powerful tool for network administrators, developers, and anyone who needs to monitor their internet connection.

Conclusion

So there you have it, folks! The Speedtest CLI is a fantastic tool for quickly and efficiently testing your internet speed right from the command line. It's perfect for anyone who loves the terminal, needs to automate speed tests, or wants a lightweight alternative to browser-based speed tests. Whether you're a network admin, a developer, or just a curious user, Speedtest CLI is a valuable addition to your toolkit. With its simple installation process and a wide range of options, you can tailor it to your specific needs and gain a deeper understanding of your network performance. So go ahead, give it a try, and see how fast your internet really is! You might be surprised at what you find. And remember, a fast internet connection is the key to a smooth and productive online experience. Happy testing!