• Traceroute is a tool/technique to list all the routers that your packets go through to reach a target.
  • The technique is to send series of packets to the target with Time to Live (TTL) set in such a way that each router on the path will have to notify you of the death of the packet.
  • The traceroute technique is based on the way the IP protocol is designed. TTL value in IP header is seen as hop limit. Everytime a router recieves a packet to forward, it decrements the TTL by one and forwards the packet. When TTL reaches 0, the router will send a reply to the source machine indicating the packet has died.
  • The technique behind various tools is same but the way they implement it slightly differs. Unix systems use UDP datagrams while the Windows tracert program uses ICMP and tcptraceroute uses TCP.

Most traceroute tools tend to send a packet with ceratin TTL value and wait for a reply before sending out the next packet which could slow down the whole process, especially when there is a network note that is unresponsive.

In this example, we are going to do a Standard ICMP Traceroute but we will send all our probes at the same time.

One obvious question, “Where do we stop?” For this exercises we’ll just send packets till TTL 30 and that is a decent number to reach almost any node on Internet.

>>> ans,unans=sr(IP(dst="",ttl=(1,10))/ICMP())

Once, we receive all probe requests we can obtain results:

>>> ans.summary( lambda(s,r) : r.sprintf("%IP.src%"))

Similarly, we can use TCP SYN traceroute to obtain similar results:


And again results would be:

>>> ans.summary( lambda(s,r) : r.sprintf("%IP.src%\t{ICMP:%ICMP.type%}\t{TCP:%TCP.flags%}"))     time-exceeded    time-exceeded     time-exceeded     time-exceeded     time-exceeded     time-exceeded         SA

Scapy includes a built-in traceroute() function to perform same functionality as above. Here is an example of TCP SYN traceroute:

>>> traceroute("")
Begin emission:
***********************Finished to send 30 packets.
Received 27 packets, got 27 answers, remaining 3 packets      
1     11 
5     11 
6     11 
7      11 
8      11 
9         RA 
10         RA 

We can perform a DNS traceroute by specifying a complete packet in l4 parameter of traceroute() function:

>>> ans,unans=traceroute("",l4=UDP(sport=RandShort())/DNS(qd=DNSQR(qname="")))
Begin emission:
..*....******...******.***...****Finished to send 30 packets.
Received 75 packets, got 28 answers, remaining 2 packets      
1     11 
4    11 
5     11 
6     11 
7      11 
8      11 

Similarly, IP Fragment traceroute can be emulated with this command:

>>> res,unans = sr(IP(dst="", ttl=(5,10), flags="MF")
...                /UDP(sport=RandShort( ), dport=53), timeout=125)
Note: I couldn't produce Type 11 Code 1 (Time Exceeded During Reassembly) ICMP error.