Skip to content

Instantly share code, notes, and snippets.

@sahinyanlik
Forked from surajchhetry/PingIP.java
Created April 14, 2016 07:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sahinyanlik/032f9f519196bb615ee014b0b0f588f4 to your computer and use it in GitHub Desktop.
Save sahinyanlik/032f9f519196bb615ee014b0b0f588f4 to your computer and use it in GitHub Desktop.
Java program to ping an IP address
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class PingIP {
public static void runSystemCommand(String command) {
try {
Process p = Runtime.getRuntime().exec(command);
BufferedReader inputStream = new BufferedReader(
new InputStreamReader(p.getInputStream()));
String s = "";
// reading output stream of the command
while ((s = inputStream.readLine()) != null) {
System.out.println(s);
}
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
String ip = "google.com";
runSystemCommand("ping " + ip);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment