本文介绍了在ping命令旁边,使用IP地址计算Java往返时间的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经实现了一种使用以下代码在Unix系统上的Java中获取RTT的方法:

I've implemented a way to get the RTT in Java on unix systems with the following code:

String command[] = {"ping", "-c4", theIPAddress};
ProcessBuilder pb = new ProcessBuilder(command);
pb.redirectErrorStream(true);
Process p = pb.start();
BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line;
while((line = in.readLine()) != null)
   //the terminal output with the ping results...
etc...

这很好用,我可以用输出以毫秒为单位计算RTT(延迟).但是,如果主机阻止了ICMP,则ping将超时. (甚至在Mac OS X终端机或Windows CMD中也是如此.)

This works fine and I can calculate the RTT (delay) in ms with the output.However, if a host has blocked ICMP, the ping will time-out. (Even in the Mac OS X Terminal or Windows CMD.)

现在,我想找到一种替代方法,以某种方式获取IP地址的RTT/延迟. (我不想在主机端安装软件.)如果您无法提供Java示例,请提供其他输入.我可以在多种语言之间进行翻译,而且确实可以使用Google.

Now I want to find an alternative way to somehow get the RTT/delay for an IP-address. (I don't want to install software on the host side.)If you can't provide me a Java example, please give me other input. I can translate between many languages, and I really can use Google.

推荐答案

Tracert是treaceroute的缩写(我最后检查过Windows命令),这只是路径ping-它也使用ICMP.

Tracert is short for treaceroute (and is windows command last I checked), what is just path ping - it also uses ICMP.

在linux上,等效命令为tracepath,在类似Unix的操作系统上,默认情况下,traceroute实用程序使用目标端口号为33434至33534的用户数据报协议(UDP)数据报. .Windows中的traceroute实用程序通常具有option来指定使用 ICMP 回显请求(类型8),如Windows tracert实用程序所使用.

On linux the equivalent command is tracepath and on Unix-like operating systems, the traceroute utility by default uses User Datagram Protocol (UDP) datagrams with destination port numbers from 33434 to 33534. The traceroute utility usually has an option to specify use of ICMP echo request (type 8) instead, as used by the Windows tracert utility.

也有使用TCP数据包的traceroute实现,例如tcptraceroutelayer four traceroute.

There are also traceroute implementations that use TCP packets, such as tcptraceroute or layer four traceroute.

来源:跟踪路由

这篇关于在ping命令旁边,使用IP地址计算Java往返时间的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-14 09:24