JAVA如何做到这条要求,目前代码输入网址和数据包次数可以返还结果,如何提取这个结果中的time信息
package ping;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.util.Scanner;
public class Ping {
public static boolean ping(String ipAddress) throws Exception {
int timeOut = 3000 ; //超时应该在3钞以上
boolean status = InetAddress.getByName(ipAddress).isReachable(timeOut); // 当返回值是true时,说明host是可用的,false则不可。
return status;
}
public static void ping02(String ipAddress,int nofecho) throws Exception {
String line = null;
try {
Process pro = Runtime.getRuntime().exec("ping " + "/n " + nofecho + " " +ipAddress );
BufferedReader buf = new BufferedReader(new InputStreamReader(
pro.getInputStream()));
while ((line = buf.readLine()) != null)
System.out.println(line);
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
}
public static void main(String[] args) throws Exception {
Scanner in = new Scanner(System.in);
String ipAddress = in.nextLine();
int nofecho = in.nextInt();
ping02(ipAddress,nofecho);
}
}