Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/401.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 我想获得ping执行时间,并在ping主机之后生成字符串_Java_Ping - Fatal编程技术网

Java 我想获得ping执行时间,并在ping主机之后生成字符串

Java 我想获得ping执行时间,并在ping主机之后生成字符串,java,ping,Java,Ping,我想得到ping执行时间和ping主机后的字符串结果。我怎么做呢?你检查过这个了吗 及 但这将仅在windows系统中使用ICMP ping。我就是这样使用它的- long start = System.currentTimeMillis(); long ping; String[] command = { "cmd.exe", "/C", "ping 192.168.1.101" }; commandProcess = Runtime.getRuntime().exec(comma

我想得到ping执行时间和ping主机后的字符串结果。我怎么做呢?

你检查过这个了吗


但这将仅在windows系统中使用ICMP ping。

我就是这样使用它的-

long start = System.currentTimeMillis();
long ping;




String[] command = { "cmd.exe", "/C", "ping 192.168.1.101" };
commandProcess = Runtime.getRuntime().exec(command);
BufferedReader buffy = new BufferedReader(new InputStreamReader(commandProcess.getInputStream()));
String readline;
while((readline = buffy.readLine())!=null){
System.out.println(readline);
if(readline.contains("reply")){
 long ping = System.currentTimeMillis();
 System.out.println("Pinged in:"+ ping);
 }
}
 long end = System.currentTimeMillis();
 String done = "Completed in times:" +start + ping +end;
private static void checkPing(String hostName) {

    String[] command = { "cmd.exe", "/C", "ping " + hostName };
    try {
        Process p = Runtime.getRuntime().exec(command);
        BufferedReader buff = new BufferedReader(new InputStreamReader(p.getInputStream()));
        String readline;
        while ((readline = buff.readLine()) != null) {
            if (readline.contains("Reply")) {
                System.out.println("Pinged " + hostName + " in : "
                        + readline.substring(readline.indexOf("time=") + 5, readline.indexOf("ms")) + " ms");
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}
提供每个ping请求的精确(可靠)ping延迟(以毫秒为单位)。 如果需要,您可以添加其中的四个

private static void checkPing(String hostName) {

    String[] command = { "cmd.exe", "/C", "ping " + hostName };
    try {
        Process p = Runtime.getRuntime().exec(command);
        BufferedReader buff = new BufferedReader(new InputStreamReader(p.getInputStream()));
        String readline;
        while ((readline = buff.readLine()) != null) {
            if (readline.contains("Reply")) {
                System.out.println("Pinged " + hostName + " in : "
                        + readline.substring(readline.indexOf("time=") + 5, readline.indexOf("ms")) + " ms");
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}