Linux traceroute Countries

1

1

Okay I was searching now for quite some time and I can't believe it. Is there no traceroute that shows me the hops on a world map? And maybe in a 64bit version

I found xtraceroute, grace, GTrace... but they are all a little bit rusty.

Maybe I'm just too stupid

Anybody knows something

megaflux

Posted 2010-10-11T03:56:57.137

Reputation: 21

Answers

1

Assuming there are freely downloadable GeoIP databases, free bindings for such databases for almost any programming language and libraries that allow to plot dots on a world map, you could try to implement your own visual traceroute. This is a great idea for a small project.

Edit: while this answer is more suitable for StackOverflow, here's a very raw visual traceroute app written in Python. While it works for me on Linux, it won't work for everyone, because it has a lot of drawbacks:

  • it uses quite a few third-party Python libraries, which need to be installed. You'll get Import Error if you don't have them
  • it doesn't bundle the world map image it uses [ I grabbed a free image from wikipedia :) ]
  • it doesn't bundle the geoip database it uses [ I'm using the free one from maxmind.com ]
  • it it is supposed to be run on Linux which has mtr installed
  • it uses hardcoded filenames for temporary files

Here is the code:

#!/usr/bin/env python

"""visual traceroute"""

import subprocess
import sys
import time

from PyQt4.QtCore import *
from PyQt4.QtGui import *

import pygeoip

import wugeo

GEOIPDB = "GeoLiteCity.dat"

class MyForm(QDialog):

    """Main app window"""

    def __init__(self, parent = None):

        """doc"""

        super(MyForm, self).__init__(parent)
        self.setWindowTitle("Visual Route")
        self.image_label = QLabel(self)
        self.image_label.setMinimumSize(800, 600)
        self.image_label.setAlignment(Qt.AlignCenter)
        self.load_image("map.jpg")
        self.ip_edit = QLineEdit(self)
        self.tr_button = QPushButton("Traceroute", parent=self)
        layout = QVBoxLayout()
        layout.addWidget(self.image_label)
        layout.addWidget(self.ip_edit)
        layout.addWidget(self.tr_button)
        self.setLayout(layout)

        self.connect(self.tr_button, SIGNAL("clicked()"), self.traceroute)

    def load_image(self, file_name):

        """Loads an image"""

        image = QImage(file_name)
        self.image_label.setPixmap(QPixmap.fromImage(image))
        self.repaint()

    def traceroute(self):

        """Do the traceroute thing"""

        self.tr_button.setEnabled(False)
        ip = self.ip_edit.text()
        p = subprocess.Popen(["sudo", "/usr/sbin/mtr", "-n", "-c", "1",
            "--raw", ip], stdout=subprocess.PIPE)
        output = p.communicate()[0]
        lines = output.split("\n")
        ip_lines = lines[::2][:-1] # filter odds, skip last
        ips = [x.split()[2] for x in ip_lines]
        coords = self.get_coords(ips)
        self.draw_dots(coords)
        self.tr_button.setEnabled(True)

    @staticmethod
    def get_coords(ips):

        """Get coords using pygeoip"""

        coords = []
        geoip = pygeoip.GeoIP(GEOIPDB, pygeoip.MMAP_CACHE)
        for ip in ips:
            record = geoip.record_by_addr(ip)
            latitude = record["latitude"]
            longitude = record["longitude"]
            location = (latitude, longitude, 1, "red")
            coords.append(location)

        return coords

    def draw_dots(self, coords):

        """Draws dots on the world map
           Uses temporary files (ugly!)"""

        infile = "map.jpg"
        outfile = "/tmp/outmap.jpg"
        for coord in coords:
            wugeo.geo_marker([coord], infile, outfile)
            self.load_image(outfile)
            time.sleep(1)
            infile = outfile

def main():

    """Main function"""

    app = QApplication(sys.argv)
    form = MyForm()
    form.show()
    app.exec_()

if __name__ == "__main__":
    main()

vtest

Posted 2010-10-11T03:56:57.137

Reputation: 4 424

0

visualroute may have a linux version ? Not sure, google seems to say yes, their site seems like no. - Its shareware anyhow though.

Sirex

Posted 2010-10-11T03:56:57.137

Reputation: 10 321