Skip to content

Instantly share code, notes, and snippets.

@atechcrew
Created July 9, 2018 16:36
Show Gist options
  • Save atechcrew/0944684f4d907b01db676cf90f13401c to your computer and use it in GitHub Desktop.
Save atechcrew/0944684f4d907b01db676cf90f13401c to your computer and use it in GitHub Desktop.
Ping your web site and IP using java. Java code to make ping to website or IP. Ping tool in java.
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class PingIP {
public static void main(String args[]) {
System.out.print("Variable Ping Starts:");
variablePing(5);
System.out.println("Variable Ping Ends\n");
System.out.print("Unlimited Ping Starts:");
UnlimitedPing();
System.out.println("Unlimited Ping Starts:");
}
public static void variablePing(int pingCount) {
try {
Process p = Runtime.getRuntime().exec("ping www.infits.pk -t");
BufferedReader inputStream = new BufferedReader(new InputStreamReader(p.getInputStream()));
String s = "";
int response = 0;
while ((s = inputStream.readLine()) != null && response < pingCount) {
System.out.println(s);
response++;
}
} catch (Exception e) {
e.printStackTrace();
}
}
public static void UnlimitedPing() {
try {
Process p = Runtime.getRuntime().exec("ping www.infits.pk -t");
BufferedReader inputStream = new BufferedReader(new InputStreamReader(p.getInputStream()));
String s = "";
while ((s = inputStream.readLine()) != null) {
System.out.println(s);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment