// Ping Command
// pingcmd.java
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class pingcmd
{
public
static void runSystemCommand(String command)
{
try
{
Process
p = Runtime.getRuntime().exec(command);
BufferedReader
inputStream = new BufferedReader(
new
InputStreamReader(p.getInputStream()));
String
s = "";
while
((s = inputStream.readLine()) != null)
System.out.println(s);
}
catch
(Exception e)
{
}
}
public
static void main(String[] args)
{
//
String ip = "www.google.co.in";
//
String ip = "127.0.0.1";
String
ip = "www.drranurekha.com";
runSystemCommand("ping
" + ip);
}
}
Sample Output:
>javac
pingcmd.java
>java
pingcmd
Pinging drranurekha.com [160.153.137.167]
with 32 bytes of data:
Reply from 160.153.137.167: bytes=32
time=167ms TTL=45
Reply from 160.153.137.167: bytes=32
time=167ms TTL=45
Reply from 160.153.137.167: bytes=32
time=167ms TTL=45
Reply from 160.153.137.167: bytes=32
time=167ms TTL=45
Ping statistics for 160.153.137.167:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in
milli-seconds:
Minimum = 167ms, Maximum = 167ms, Average = 167ms
>
No comments:
Post a Comment
Don't be a silent reader...
Leave your comments...
Anu