Speedtest CLI: Test Your Internet Speed From The Command Line

by Jhon Lennon 62 views

Hey guys! Ever wondered how to check your internet speed without opening a browser? Well, let me introduce you to the Speedtest CLI – a command-line interface for the popular Speedtest.net service. It's a nifty tool for you tech enthusiasts and network admins who love the terminal. In this article, we'll dive deep into what Speedtest CLI is, how to install it, and how to use it effectively. So, buckle up and get ready to boost your command-line skills!

What is Speedtest CLI?

Speedtest CLI is the command-line version of the well-known Speedtest.net, a web service provided by Ookla. It allows you to perform internet speed tests directly from your terminal or command prompt. Instead of opening a web browser and navigating to the Speedtest website, you can simply run a command in your terminal to get your download speed, upload speed, ping, and other network-related information. This tool is super handy for those who prefer using the command line, automating speed tests via scripts, or running tests on servers without a graphical user interface. Plus, it gives you a consistent and reliable way to measure your internet connection's performance.

One of the major advantages of using Speedtest CLI is its automation capabilities. Imagine you want to monitor your internet speed at different times of the day. With Speedtest CLI, you can create a simple script that runs the speed test at specified intervals and logs the results. This can be incredibly useful for identifying peak hours when your internet speed might be slower than usual. Moreover, the CLI tool eliminates the need to manually navigate through a website, click on buttons, and interpret the results from a graphical interface. Everything is presented in a clear, text-based format, making it easy to parse and analyze the data. For network administrators, this means they can quickly diagnose network issues, verify service level agreements (SLAs) with ISPs, and ensure that their network infrastructure is performing optimally.

Another cool feature is the ability to specify different Speedtest servers. By default, the CLI tool selects the nearest server to perform the test, but you can also manually specify a server ID to test your connection to a specific location. This can be useful if you're trying to troubleshoot connectivity issues to a particular server or if you simply want to see how your connection performs with different endpoints. The Speedtest CLI provides a simple way to list available servers and their corresponding IDs, allowing you to choose the most appropriate server for your needs. In summary, the Speedtest CLI is a powerful and versatile tool that brings the convenience of Speedtest.net to your command line, offering a range of options for testing and monitoring your internet connection.

Installation

Getting Speedtest CLI up and running is a breeze. The installation process varies slightly depending on your operating system, but don't worry, I've got you covered. Here's how to install it on different platforms:

Windows

  1. Download the Executable:
  2. Extract the File:
    • Once the download is complete, extract the contents of the ZIP file to a directory of your choice (e.g., C:\Speedtest).
  3. Add to Path (Optional but Recommended):
    • To run the speedtest command from any location, you need to add the directory containing the executable to your system's PATH environment variable.
    • Search for "environment variables" in the Start menu and click on "Edit the system environment variables."
    • Click on "Environment Variables..." button.
    • In the "System variables" section, find the Path variable, select it, and click "Edit..."
    • Click "New" and add the path to the directory where you extracted the Speedtest CLI executable (e.g., C:\Speedtest).
    • Click "OK" on all windows to save the changes.
  4. Test the Installation:
    • Open a new command prompt or PowerShell window.
    • Type speedtest -v and press Enter. If the installation was successful, you should see the Speedtest CLI version number.

macOS

  1. Using Homebrew (Recommended):

    • If you have Homebrew installed, simply open your terminal and run:

    brew install speedtest-cli

  2. Using the Installer:

    • Go to the official Speedtest CLI download page (https://www.speedtest.net/apps/cli).
    • Download the macOS installer.
    • Open the downloaded .pkg file and follow the on-screen instructions to install Speedtest CLI.
  3. Test the Installation:

    • Open a new terminal window.
    • Type speedtest -v and press Enter. If the installation was successful, you should see the Speedtest CLI version number.

Linux

  1. Download the Binary:

    • Go to the official Speedtest CLI download page (https://www.speedtest.net/apps/cli).
    • Download the appropriate Linux binary for your system architecture (e.g., 32-bit or 64-bit).
  2. Extract the File:

    • Extract the contents of the downloaded file to a directory of your choice (e.g., /usr/local/bin).
  3. Make it Executable:

    • Open your terminal and navigate to the directory where you extracted the Speedtest CLI binary.
    • Run the following command to make the binary executable:

    chmod +x speedtest

  4. Add to Path (Optional but Recommended):

    • To run the speedtest command from any location, you can add the directory containing the executable to your system's PATH environment variable.
    • Edit your shell's configuration file (e.g., .bashrc, .zshrc) and add the following line:

    export PATH=$PATH:/path/to/speedtest

    • Replace /path/to/speedtest with the actual path to the directory where you extracted the Speedtest CLI binary.
    • Save the file and reload your shell configuration by running:

    source ~/.bashrc or source ~/.zshrc

  5. Test the Installation:

    • Open a new terminal window.
    • Type speedtest -v and press Enter. If the installation was successful, you should see the Speedtest CLI version number.

With these steps, you should have Speedtest CLI successfully installed on your system. Now, let's move on to using it!

Basic Usage

Alright, now that you've got Speedtest CLI installed, let's get down to the nitty-gritty of how to use it. The basic usage is super simple. Just open your terminal or command prompt and type speedtest followed by any options you want to use. Here are some common examples to get you started:

Running a Simple Speed Test

The most basic command to run a speed test is simply:

speedtest

This command will run a standard speed test using the nearest Speedtest server and display the results in your terminal. The output will include your download speed, upload speed, ping (latency), and other relevant information. It's a quick and easy way to get a snapshot of your internet connection's performance.

Displaying Results in Bytes Instead of Bits

By default, Speedtest CLI displays the results in bits per second (bps). If you prefer to see the results in bytes per second (Bps), you can use the --bytes option:

speedtest --bytes

This can be useful if you're more familiar with measuring data transfer rates in bytes. Keep in mind that 1 byte is equal to 8 bits, so the values will be different, but they represent the same speed.

Getting a Shareable Link to the Results

If you want to share your speed test results with others, you can use the --share option to generate a shareable link:

speedtest --share

This command will run the speed test and then generate a URL that you can share with anyone. When someone clicks on the link, they'll see a graphical representation of your speed test results on the Speedtest.net website. It's a convenient way to share your results on social media, forums, or with your ISP if you're having connectivity issues.

Specifying a Specific Server

As mentioned earlier, you can specify a particular Speedtest server to use for your test. First, you need to find the server ID of the server you want to use. You can do this by running:

speedtest --list

This command will display a list of available Speedtest servers, along with their IDs, names, and distances from your location. Once you have the server ID, you can use the --server option to specify it in your speed test command:

speedtest --server <server_id>

Replace <server_id> with the actual server ID you want to use. This can be helpful if you want to test your connection to a specific server or if you're troubleshooting connectivity issues to a particular location.

Getting Help

If you're ever unsure about how to use Speedtest CLI, you can always use the --help option to display a list of available commands and options:

speedtest --help

This will show you all the available options and a brief description of what each one does. It's a handy way to quickly look up the syntax for a particular command or to discover new features that you might not have known about.

Advanced Options

Now that we've covered the basics, let's delve into some more advanced options that Speedtest CLI offers. These options can help you fine-tune your speed tests and get more detailed information about your network connection.

Saving Results to a File

If you want to save your speed test results for later analysis or record-keeping, you can redirect the output of the speedtest command to a file. This can be done using the standard command-line redirection operators. For example, to save the results to a file named speedtest_results.txt, you can use the following command:

speedtest > speedtest_results.txt

This will run the speed test and save the output to the specified file. You can then open the file in a text editor to view the results. If you want to append the results to the file instead of overwriting it, you can use the >> operator:

speedtest >> speedtest_results.txt

This is useful if you want to keep a history of your speed test results over time.

Using a Custom Configuration File

Speedtest CLI allows you to customize its behavior using a configuration file. This can be useful if you want to set default options that you don't want to have to specify on the command line every time you run a speed test. The configuration file is typically located in your home directory and is named .speedtest_cli.json. You can create this file manually or use the --config option to generate a default configuration file:

speedtest --config

This will create a default configuration file in your home directory. You can then edit the file to customize various settings, such as the default server, the preferred unit of measurement (bits or bytes), and other options. Once you've configured the settings in the configuration file, they will be applied automatically every time you run Speedtest CLI.

Running a Speed Test Non-Interactively

In some cases, you may want to run a speed test non-interactively, without any user input or output. This can be useful if you're running Speedtest CLI from a script or in an automated environment. To run a speed test non-interactively, you can use the --non-interactive option:

speedtest --non-interactive

This will run the speed test and display the results in a minimal format, without any prompts or progress messages. The output will typically consist of a single line containing the download speed, upload speed, and ping, separated by commas or other delimiters. This format is easy to parse and can be used to extract the results programmatically.

Ignoring Errors

By default, Speedtest CLI will exit with an error code if any errors occur during the speed test. This can be useful for detecting and handling errors in your scripts or automated environments. However, in some cases, you may want to ignore errors and continue running the script even if the speed test fails. To ignore errors, you can use the --ignore-errors option:

speedtest --ignore-errors

This will cause Speedtest CLI to continue running even if errors occur. Keep in mind that ignoring errors may result in incomplete or inaccurate results, so use this option with caution.

Conclusion

So there you have it, folks! Speedtest CLI is a powerful and convenient tool for testing your internet speed directly from the command line. Whether you're a tech enthusiast, a network admin, or just someone who wants to quickly check their internet speed, Speedtest CLI has something to offer. With its ease of installation, simple usage, and advanced options, it's a must-have tool in your arsenal. So go ahead, give it a try, and see how fast your internet connection really is! Remember to explore the different options and customize the tool to fit your specific needs. Happy testing!