I am writing a Java program that pings IP, and here I need to take the result from time, TTL, byte and timestamp, by default it gives, for example: 64 bytes from 87.240.131.119: icmp_seq = 1 ttl = 59 time = 38.6 ms Code of the ping function :
static void runSystemCommand(String command, String addr) { try { Process p = Runtime.getRuntime().exec(command); BufferedReader inputStream = new BufferedReader( new InputStreamReader(p.getInputStream())); String s = ""; File file = new File("res//" + addr + ".json"); FileWriter writer = new FileWriter(file, true); int i = 0; while ((s = inputStream.readLine()) != null && i < 2) { writer.write(s + "\n"); System.out.println(s); i++; } writer.close(); } catch (Exception e) { e.printStackTrace(); } }
inputStream? The ping output format is simple. It is easy to compose a regular expression and check every lineson it, extractingttlif it matches - Sergey