Files
nudtns2026spring/Sniffing_Spoofing/Labsetup/volumes/traceroute.py
2026-04-07 20:49:20 +08:00

21 lines
514 B
Python

#!/usr/bin/env python3
from scapy.all import *
target = "8.8.8.8"
print(f"Traceroute to {target}...")
for i in range(1, 31):
pkt = IP(dst=target, ttl=i) / ICMP()
reply = sr1(pkt, verbose=0, timeout=1)
if reply is None:
print(f"{i}: * * *")
elif reply.type == 3: # Destination unreachable
print(f"{i}: {reply.src} (Unreachable)")
break
else:
print(f"{i}: {reply.src}")
if reply.src == target:
print("Reached target!")
break