I'm trying to build a tracert with python. I made a loop that runs ttl times to show all the source ip's that the message has passed.
I understand that there are some "stations" that doesn't return ttl exceeded, so I need to create a timeout request with the srp, I don't really know what does srp1(msg, timeout = 10) will return to me because I cant see the returned message
I got the TTL size to run in the loop, just need to know what do to if timeout passed.
for i in range(1,ttl+1):
msg = Ether() / IP(dst = domain, ttl = i) / ICMP()
ans = srp1(msg, verbose = 0, timeout = 10)
print("%d: %s" % (i, ans[IP].src))
If a timeout occurs srp1 will return None.
if ans is not None:
print("%d: %s" % (i, ans[IP].src))
else:
print("%d: Timeout waiting for %s" % (i, fullmsg[IP].dst))
timeout=2 should be a good value.