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(); } } 
  • Well, let the timestamp and time be calculated, but what to do with TTL and byte (as far as I can see, there is a 64-bit packet sent all the time, but I don’t want magic numbers)? - Ivan
  • one
    Do you get ping output in inputStream ? The ping output format is simple. It is easy to compose a regular expression and check every line s on it, extracting ttl if it matches - Sergey
  • Thank. But it does not ... Can you set an example of how to do this? I just met today with regular expressions, I have never met before. - Ivan
  • You are welcome. Write a question asking for a regular ping expression. You will certainly zaminusyut, but on the other hand there is someone who can help. Though I am not minus, I am not making regulars for someone. - Sergey
  • No, not for ping, but how to cut part of the string and save. Well, I get it - Ivan

0