我正在学习计算机网络,正在寻找一种使用命令模拟 traceroute 的方法ping
。我认为这与 ttl 有关,但我不知道如何进一步开发它。
答案1
有一种方法可以做到这一点。
在 Linux 或 Cygwin 中:
for i in {1..30}; do ping -t $i -c 1 google.com; done | grep "Time to live exceeded"
在 Windows 中:
for /l %i in (1,1,30) do @ping -i %i -n 1 google.com | find "TTL expired"
来自 Amazon EC2 VPS 的示例输出:
From 100.64.16.93 icmp_seq=1 Time to live exceeded
From 205.251.232.220 icmp_seq=1 Time to live exceeded
From 205.251.232.202 icmp_seq=1 Time to live exceeded
From 205.251.232.75 icmp_seq=1 Time to live exceeded
From 205.251.225.181 icmp_seq=1 Time to live exceeded
From 72.14.219.251 icmp_seq=1 Time to live exceeded
From 209.85.249.32 icmp_seq=1 Time to live exceeded
From 216.239.51.159 icmp_seq=1 Time to live exceeded
该实例不允许 Ping,这就是它超时的原因。