Run traceroute with HTTP using the Globalping API

Do you need to visualize the network path to a service or pinpoint a bottleneck from an environment where you can't run traceroute, such as your web app or serverless function?

We're here to help you tackle this challenge by showing you a way to run traceroute with HTTP. We'll demonstrate how to leverage the Globalping API to perform traceroute from any environment that allows you to make an HTTP request.

The problem: why you may have issues running traceroute

Traceroute is a popular network diagnostic tool that sends a series of packets with increasing Time-to-Live (TTL) values using UDP, TCP, or ICMP to a target host. It then maps the path the packets take across the network. For each hop (router), traceroute collects its IP address and measures the time it takes to reach it, which makes traceroute great for finding routing issues and performance bottlenecks.

However, there are times when the traditional traceroute tool doesn't deliver the expected results or doesn't work at all:

  • Firewall and router filtering: Some network devices are configured to drop or limit the "Time Exceeded" messages that traceroute relies on. This often results in 'asterisks' (* * *) in the output, indicating that hops are unresponsive, leaving you with an incomplete or misleading picture of the network path from your specific vantage point.
  • Environmental limits: Traceroute typically requires direct access to system network protocols, which are not available in many modern technical environments, such as client-side JavaScript, serverless functions, and edge applications.

Considering the valuable information that traceroute provides, it can be quite a headache if you're unable to use it when and where you need it. But what if you could just run traceroute with HTTP?

The solution: the Globalping API

This is where Globalping comes in to save your day. The platform operates a vast probe network, mostly hosted by our community members and partners around the world. Thanks to this network, anyone can run network measurements, such as ping, traceroute, mtr, dig, and curl, from virtually any location for free. Additionally, Globalping is open-source, offers high API limits, and provides various tools, including a CLI, GitHub bot, and API, to offer users flexible access to its capabilities.

The Globalping API is the foundation that powers all our integrations and tools, and it's also available for you to use directly, especially if you need to programmatically trigger network measurements.

Using our API, you can easily overcome the problems we just talked about:

  • Firewall and router filtering: While Globalping can't make a non-responsive router suddenly start replying, it allows you to run traceroute from different locations. This can help you better understand these path issues and maybe even help you discover alternative, clearer routes that you wouldn't find by running traceroute from your location.
  • Environmental accessibility: To use the API, you simply need the ability to run an HTTP request. Globalping's API and probes will take care of creating, collecting, and returning the traceroute results for you.

How to run traceroute with HTTP using Globalping

In this section, we'll show you how to use the "Try" functionality in Globalping's API reference to create your first network measurement using traceroute.

But before we start, here are a couple of things to keep in mind:

  • Authentication: You don't need to authenticate to use the API. However, we recommend signing up for the Globalping Dashboard and then authenticating your API requests to take advantage of increased API limits. Check the Globalping API reference for details on authentication.
  • API limits: Our limits apply to the number of tests you run, not just the number of API requests you send. For example, if you run a traceroute from four locations with one API request (one measurement), it'll count as four tests against your API limit. Also, if not authenticated, the API limits apply per IP address. This means if you use the API from client-side JavaScript, each of your users will have their own API limit.

To create a traceroute test and gran its results, we're going to use two API endpoints:

  • POST /measurements: We use this endpoint to create a new measurement with traceroute.
  • GET /measurements/{id}: Once the measurement is created, we'll use this endpoint to retrieve its results.

Triggering a basic traceroute with HTTP

For our first example, let's say we want to see the network path to globalping.io from a probe in London and another in Japan.

Step 1: Create the measurement

To create and trigger the test, we'll need to send a POST request to the /measurements endpoint and provide it with a JSON request body containing our traceroute test details:

To run a traceroute with HTTP, create a new measurement with the Globalping API.

The respective curl command:

curl -X POST https://api.globalping.io/v1/measurements \
  --header 'Content-Type: application/json' \
  --data '{
    "target": "globalping.io",
    "type": "traceroute",
    "locations": [
      {"country": "JP"},
      {"city": "London"}
    ]
  }'

If everything goes well, the API will return a JSON response that includes the measurement ID. Make sure to copy this ID, as we'll need it in the next step.

Once Globalping created your measurement, the API returns the measurement ID.

The respective curl:

curl -X GET https://api.globalping.io/v1/measurements/your-measurement-id-goes-here

Step 2: Get the measurement results

Network measurements can take a few seconds to finish up. You can check the status attribute in the response: once it's anything other than in_progress, the final results are ready to be viewed.

💡
Important: If you're building an application and want to fetch results automatically, we highly recommend following our polling best practices to avoid exceeding your API limits.

Now, let's retrieve the measurement result by providing our measurement ID to the endpoint:

You can find information about the probes and the traceroute results in the API's response.

Here's what you'll find in that response:

  • results.probe: This section contains information about the probe that ran the test. This includes the geographical location, ASN, and DNS resolvers.
  • results.result: This is where you can find the traceroute results.
    • rawOutput: the raw text output of the traceroute test results, just like you'd see it in your Linux terminal.
    • hops: lists details about each router along the path, including its IP address and round-trip times (RTT).

More use cases and examples

Now that you understand how to use the API let's explore what else you can do. Let's look at additional examples that show the different results you can achieve by tweaking the data you include in your request body.

Trace paths from specific cloud infrastructure

Understanding how traffic flows through specific cloud providers or network environments can be important. The API lets you target probes right within those specific networks to verify your routing paths.

Let's say you want to verify the route from an AWS region in the US East to your app:

{
    "target": "globalping.io",
    "type": "traceroute",
    "locations": [
        {
            "country": "US",
            "tags": [
                "aws-us-east-1"
            ]
        }
    ]
}

Simplify probe targeting with "magic"

The magic field allows you to provide location data as a simple string, and the API does its best to pick fitting probes that match your input. This often makes targeting probes much more straightforward.

For example, in our AWS example above, you had to know the tag aws-us-east-1. With the magic field, you could simply write {"magic": "US+AWS"}, where the + sign tells Globalping to combine those filters to find probes that are both in the US and on the AWS network.

Here are some more magic examples:

{
    "target": "globalping.io",
    "type": "traceroute",
    "locations": [
        {
            "magic": "US+Comcast"
        },
        {
            "magic": "AS13335"
        },
        {
            "magic": "JP+Google"
        }
    ]
}

💡
Tip: You can also choose not to provide any location data and have the API pick a random probe for you.

Control probe count per location

If you list multiple locations in your measurement request, the API will select one probe from each. But what if you want to run more than one probe from a specific area? This is where the limit option comes in handy!

Let's say you want to get a few traceroute results from Europe and also a couple from Brazil:

{
    "target": "globalping.io",
    "type": "traceroute",
    "locations": [
        {
            "continent": "EU",
            "limit": 3
        },
        {
            "country": "BR",
            "limit": 4
        }
    ]
}

Make use of command-specific options

Most Globalping commands allow you to define additional command-specific options to fine-tune your test.

Under measurementOptions you can define these options for traceroute:

  • port: The destination port for the data packets.
  • protocol: Use ICMP, TCP, or UDP as the transport protocol for the packets.
  • ipVersion (experimental): Use either IPv4 or IPv6.
{
    "target": "your-app.com",
    "type": "traceroute",
    "measurementOptions": {
        "protocol": "udp",
        "port": 33434
    }
}

Conclusion

After walking through this guide, you should now feel confident about running traceroute with HTTP using the Globalping API. This means you are no longer stuck and can perform vital network measurements from any environment that can make an HTTP request, whether it's your JavaScript app or Edge app.

We invite you to try and experiment with Globalping to see for yourself how much easier it can make your network troubleshooting and path discovery tasks.

If you're looking to integrate this functionality more deeply into your projects, especially in Node.js environments like edge computing workloads, check out our TypeScript library.

Otherwise, head over to the Globalping API and use the "Try" functionality to play around with some tests for free.