Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Scapy Traceroute

import sys
import scapy.all as scapy

target = '8.8.8.8'
if len(sys.argv) == 2:
    target = sys.argv[1]

ans, unans = scapy.sr(scapy.IP(dst=target, ttl=(1,22),id=scapy.RandShort())/scapy.TCP(flags=0x2), timeout=10)
for snd,rcv in ans:
    print(snd.ttl, rcv.src, isinstance(rcv.payload, scapy.TCP))