I want to get the ping execution time and result in string after ping host

前端 未结 4 1984
醉梦人生
醉梦人生 2021-01-13 14:10

I want to get the ping execution time and result in string after ping host. How can I do it?

4条回答
  •  南笙
    南笙 (楼主)
    2021-01-13 14:29

    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;
    

提交回复
热议问题