Created
July 9, 2018 16:36
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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