Ping commands in Java

String cmd = "cmd.exe /c ping 8.8.8.8"; //Command to execute

Runtime runtime = Runtime.getRuntime();

Process p = runtime.exec(cmd);

InputStream is = p.getInputStream();
InputStreamReader isr = new InputStreamReader(is, "Shift-JIS");
BufferedReader reader = new BufferedReader(isr);

for (String line; (line = reader.readLine()) != null;) {
	System.out.println(line);
}

output

8.8.8.Pinging to 8 32 bytes of data:
8.8.8.Response from 8:Number of bytes=32 hours=15ms TTL=57
8.8.8.Response from 8:Number of bytes=32 hours=13ms TTL=57
8.8.8.Response from 8:Number of bytes=32 hours=12ms TTL=57
8.8.8.Response from 8:Number of bytes=32 hours=13ms TTL=57

8.8.8.8 ping stats:
Number of packets:Send=4, receive=4, loss= 0 (0%Loss)、
Approximate round trip time(millisecond):
minimum=12ms, maximum=15ms, average= 13ms

Recommended Posts

Ping commands in Java
Partization in Java
Changes in Java 11
Rock-paper-scissors in Java
Pi in Java
FizzBuzz in Java
About Java commands
[java] sort in list
Read JSON in Java
Interpreter implementation in Java
Make Blackjack in Java
Rock-paper-scissors app in Java
Constraint programming in Java
Put java8 in centos7
NVL-ish guy in Java
Combine arrays in Java
"Hello World" in Java
Comments in Java source
Azure functions in java
Format XML in Java
Simple htmlspecialchars in Java
Boyer-Moore implementation in Java
Hello World in Java
Use OpenCV in Java
Type determination in Java
Various threads in java
Heapsort implementation (in java)
Zabbix API in Java
ASCII art in Java
Compare Lists in Java
POST JSON in Java
Express failure in Java
Create JSON in Java
Date manipulation in Java 8
What's new in Java 8
Use PreparedStatement in Java
What's new in Java 9,10,11
Parallel execution in Java
Initializing HashMap in Java
Try using RocksDB in Java
Read binary files in Java 1
Avoid Yubaba's error in Java
Get EXIF information in Java
Save Java PDF in Excel
[Neta] Sleep Sort in Java
Edit ini in Java: ini4j
Let Java segfault in 6 lines
Try calling JavaScript in Java
Try developing Spresense in Java (1)
Try functional type in Java! ①
I made roulette in Java.
Create hyperlinks in Java PowerPoint
Implement two-step verification in Java
Refactoring: Make Blackjack in Java
Write flyway callbacks in Java
Topic Analysis (LDA) in Java
Importing Excel data in Java 2
NEologd preprocessing in Java neologdn-java
Change java encoding in windows
Java Stream API in 5 minutes
Read standard input in Java