Thoughts on Programming

September 10, 2011

The traceroute utility

Filed under: General — shadiyya @ 6:38 am
Tags: , ,

Traceroute is a very useful debugging tool, which can be used to find a number of useful things about host, client, and routers that data passes through on its way from the source to the destination. However, Traceroute is most commonly used for network troubleshooting by finding out the path taken by an IP datagram from the source to the destination. Providing a list of routers traversed, it allows the user to identify the path taken to reach a particular destination in the network. This can help identify routing problems or firewalls that may be blocking access to a site..

How It Works

Traceroute begins by sending a UDP datagram from the originating host to the destination host with the TTL initially set to a value of 1. When the datagram arrives at the first router, that router decrements the TTL by one which results in a TTL of zero. The datagram is now expired so the router sends an ICMP Time Exceeded message to the originating host. The source address of this ICMP message is the address of the router and the destination address is the address of the originating host. This response to the originating host now gives the IP address of the first router.

The second UDP datagram sent by the originating host is exactly the same at the first but with a TTL value of 2. This time the first router receives
the datagram and decrements the TTL by 1. Since the TTL is still greater than 0, this first router now routes the datagram to the next router. The second router in turn decrements the TTL by 1 resulting in a TTL of 0. This triggers an ICMP Time Exceeded message from the second router. The source address of the ICMP message is the address of the second router and the destination address is the address of the originating host. Now the originating host knows the address of the second router also. This process continues until a maximum TTL is reached (typically around 30) or the destination host is finally reached.

            

Here is the python code:

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

Blog at WordPress.com.