2016-11-20 37 views
0

我现在有一个shell脚本,它只是需要一个URL作为参数,然后发送ping请求到它,如下所示:如何在ping网站(bash)时指定使用哪种协议(IPv4或IPv6)?

ping -c 5 $1 

,要求我来ping使用IPv4和IPv6在可能的部位,然后我会比较结果。我已经阅读了ping的手册页,并且看不到指定要使用哪种协议的标志,我期待它接受IPv4的标志-4和IPv6的-6,但似乎并非如此。

我遇到了DNS查找工具这看起来很有希望,但还没有成功地实现它在我的代码。我的脚本必须将一个URL作为参数,而不是其他参数。我希望这是清楚的,并感谢您的帮助。

+0

我的''ping'能理解'-4'和'-6',Arch Linux和Cygwin在Windows上。 – dav1d

+0

你应该也有'ping6' –

+0

谢谢保罗我不知道这个命令 – user546482872

回答

1

使用pingping6在大多数发行版中都可用。

/tmp $ dig google.com A google.com AAAA +short 
172.217.4.174 
2607:f8b0:4007:801::200e 

/tmp $ ping -c 2 172.217.4.174 
PING 172.217.4.174 (172.217.4.174): 56 data bytes 
64 bytes from 172.217.4.174: icmp_seq=0 ttl=53 time=35.619 ms 
64 bytes from 172.217.4.174: icmp_seq=1 ttl=53 time=34.220 ms 

/tmp $ ping6 -c 2 2607:f8b0:4007:801::200e 
PING6(56=40+8+8 bytes) 2602:306:b826:68a0:f40e:abca:efdb:71f --> 2607:f8b0:4007:801::200e 
16 bytes from 2607:f8b0:4007:801::200e, icmp_seq=0 hlim=55 time=77.735 ms 
16 bytes from 2607:f8b0:4007:801::200e, icmp_seq=1 hlim=55 time=81.518 ms 
+0

感谢helloV为我的注意力带来ping6,我会接受你的答案一旦堆栈溢出让我 – user546482872