

Traceroute in 15 lines of code using Scapy - jvns
http://jvns.ca/blog/2013/10/31/day-20-scapy-and-traceroute/

======
sp332
I've just started using scapy recently. The syntax is a little inconsistent,
but it's really powerful. It defines a domain-specific language (DSL) that
piggybacks on python syntax. You can make a traceroute-like object in one
line:

    
    
      pkt = IP(dst=target, ttl=(4,25),id=RandShort())/TCP(flags=0x2)
    

This single pkt object describes 22 IP packets, each with a TTL from 4 to 24
inclusive. Each IP packet encapsulates a TCP packet with the SYN flag set.

[http://www.secdev.org/projects/scapy/doc/usage.html#tcp-
trac...](http://www.secdev.org/projects/scapy/doc/usage.html#tcp-traceroute)

------
codezero
Pretty nifty. One of the things traceroute also does is to deal with broken
routers that don't send the proper replies, as well as a number of other edge
cases, but this is a cool toy and will probably work in most average cases.

see also:

[http://cluepon.net/ras/traceroute.pdf](http://cluepon.net/ras/traceroute.pdf)
and [http://blog.cachefly.com/2012/02/15/understanding-
traceroute...](http://blog.cachefly.com/2012/02/15/understanding-traceroute/)

