dotnet-ping: Ping URLs in the Terminal

When working with the web development at a rapid pace, you need to constantly ensure that key parts of your website always work. There are tools out there that offers advanced monitoring, but what about when you just want to fire off quick ensuring tests on your local machine?

This is the background to why I built dotnet-ping, which is easily installed as a .NET Global Tool and makes pinging URLs via the terminal really easy.

Installation

Download the latest version of .NET. Then install the dotnet-ping .NET Tool, using the terminal:

dotnet tool install -g dotnet-ping

Once installed, you can verify the tool is available by running dotnet tool list -g.

Basic scenarios

To ping a single URL just supply the URL as the command argument:

dotnet ping https://example.com/section/page

If you want to ping multiple URLs, you can supply multiple command arguments.

dotnet ping example.com/page other.com/other-page

If a URL is missing the protocol (e.g., http:// or https://), the tool will automatically assume https://.

You can use the -s option to set the sleep time between requests and the -t option to set the timeout limit for a response from the pinged URL.

If you want to ping multiple pages on the same website, you can supply a base-URL, using the -b option:

dotnet ping -b example.com /home /about /contact-us /products

Pings expect, by default, a 200 response as HTTP status. This can be modified with the -e option. The full list of documentation can be found by calling the tool with the -h option or looking at the README on GitHub or on NuGet.org.

Advanced scenarios

For more advanced scenarios, where you want to have a better overview and more complex configuration for multiple URLs, the tool supports configuration via a .json file. If there is a ping.json file in the directory that the tool is executed from, and no URL is passed as a command argument, this file will be used.

The basic structure of the file allows an array of URLs (urls) and their configuration, as well as an array of configuration group (groups), which are applied to one or multiple URLs.

{
    // Single URLs, with Single configurations
    "urls": [
        {
            "url": "test.com", // Required
            "method": "GET", // Default: GET
            "timeout": 15000, // Default: 5000ms
            "sleep": 100, // Default: 500ms
            "expect": [ 200, 201, 403 ] // Default: 200
        },
        {
            "url": "http://test2.com",
            "method": "DELETE",
            "timeout": 10000,
            "sleep": 200,
            "expect": [ 201, 202, 204 ]
        }
    ],
    // Groups of configurations, with single or multiple URLs
    "groups": [
        {
            "timeout": 20000,
            "sleep": 250,
            "expect": [ 301, 302 ],
            "urls": [ "test3.com/redirect", "test4.com/redirect" ]
        },
        {
            "timeout": 5000,
            "sleep": 550,
            "baseUrl": "https://test5.com/",
            "expect": [ 200, 201 ],
            "urls": [ "/", "/about", "/contact", "products" ]
        }
    ]
}

Usage Documentation

See the usage documentation of the tool by running dotnet ping -h:

USAGE:
    dotnet-ping [urls] [OPTIONS]

EXAMPLES:
    dotnet-ping https://example.com
    dotnet-ping https://example.com other.com -s 1000
    dotnet-ping https://example.com other.com -s 1000 -s 2000 -t 5000
    dotnet-ping /about /contact -b https://example.com
    dotnet-ping -c ping.json

ARGUMENTS:
    [urls]    The URLs to ping. If not specified, the URLs are read from the JSON config file

OPTIONS:
    -h, --help        Prints help information
    -b, --base-url    Sets the base-URL to use for requests
    -c, --config      The path to the JSON config file
    -d, --debug       Use debug console messaging
    -e, --expect      Sets the expected status code of requests. Default: 200
    -X, --request     Sets the request method. Default: GET
    -m, --minimal     Use minimal console messaging
    -s, --sleep       Sets the sleep wait time between requests in milliseconds. Default: 500ms
    -t, --timeout     Sets the timeout for requests in milliseconds. Default: 5000ms. If two values are provided, a
                      random number between the two numbers will be generated for each request

Outro

Take it for a spin and feel free to give feedback on the tool. If you find bugs or have suggestions, feel free to open an issue on GitHub or submit a pull request.

You can find the source-code on GitHub and the package on Nuget.

Comments