问题描述
- 这是运行 traceroute 110.242.68.3 的命令行 enter image description here
- 这是使用scapy库编写的traceroute
def tcptraceroute(host,timeout,maxttl=30):
"""tcptraceroute sends TCP messages with SYN flag set
to host with increasing TTL until it reaches destination
host or reaches maxttl
:host: traceroute's destination
"""
ip = host
print("tcptraceroute to '{}' ({}),{} hops max".format(host,ip,maxttl))
for i in range(1,maxttl + 1):
for j in range(3):
packet = IP(dst=ip,ttl=i) / TCP(flags='S')
resp,_ = sr(packet,verbose=0,timeout=timeout)
src = "*"
duration = ""
if len(resp) > 0:
src = resp[0][1].src
duration = "{:.3f} ms".format(
1000 * (resp[0][1].time - resp[0][0].sent_time))
print("{:2d}. {:>15}\t{}".format(i,src,duration))
if src == ip:
return
print("Couldn't traceroute {},reached max TTL '{}'".format(ip,maxttl))
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)