Follow me on Linkedin

Program for using Ping command

/*
Exercise : Ex 1(b)
Title : Program for using ping command..
Author :Aslam Jainul
*/

import java.net.*;
import java.io.*;
import java.net.InetAddress.*;
public class EX_1_B_Ping
{
public static void main(String args[])
{
try
{
DataInputStream obj= new DataInputStream(System.in);

System.out.println("Enter the IP/Name Address.....");

String user_str = obj.readLine();

String mystring ="ping " + user_str ;

Runtime r= Runtime.getRuntime();
Process p=r.exec(mystring);

DataInputStream obj1= new DataInputStream(p.getInputStream());

String  data=obj1.readLine();
while(data !=null )
{
System.out.println(data);
data=obj1.readLine();
}
}

catch(Exception E)
{
System.out.print("SOME ERROR OCCURED");
}
}
}

Output :


0 comments:

Post a Comment

a