Linux for Network Engineers: Plot Traceroute Path on Google Maps

By September 30, 2020Linux

Traceroute gives you the hop-by-hop information of a route from a source host to a destination. In most cases getting the IP and maybe its DNS lookup (when available) is enough for troubleshooting purposes.

Nmap is another tool that I’ve been using a lot lately. It’s very well known in the networking and infosec community and can do so much, which makes me think that only the nmap developers themselves have a grasp of the whole spectrum of its capabilities and features.

Nmap Traceroute

Nmap has a wide range of network discovery capabilities out of the box. In the context of traceroute, it can do the following:

The output looks very similar to the traceroute output you are familiar with. In addition, nmap does a port scan showing you what ports have been found open on the final host (80, 443, 8080). This run took 14.81 seconds, but if you add the option  -sP nmap doesn’t do port scanning, and in that case, nmap finishes within a few seconds.

Traceroute Hops on Google Maps

We have talked about nmap’s scripting capabilities in a previous post. Nmap has around 600 prepackages scripts that do a variety of tasks, but you can also write your own scripts tailored to your discovery or testing needs.

There are a few scripts that do traceroute geolocation, but the one I found that works more reliably and returns correct results more consistently is traceroute-gelocation.

Here is how you execute it:

The output gives me the classic traceroute result, but also the coordinates of the IPs that can be geolocated. It has to be noted that sometimes fails without providing the coordinate information.

In addition, with the option --script-args traceroute-geolocation.kmlfile=coordinates-in.kml the coordinates were saved in a KML file that can be imported to Google maps and give you a cool view of the routing. 

To do that, open Google maps, and 

  1. Go to “My Maps” (the easiest way to find that is to google “My Maps” than trying to find it through the Google maps menu options).
  2. Click on “+CREATE A NEW MAP”
  3. Click on “Import” and import the file generated from the traceroute-geolocation NSE script above
  4. Voila! 

It’s a quick and easy way to visualize a traceroute path for your convenience, for showing it to customers, or for educational purposes.