Program in java for Ping
Program:
import java.io.*;
import java.net.*;
import java.util.*;
class ping
{
public static void main(String ar[]) throws Exception
{
try{
String str;
BufferedReader buf=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the ip address");
String ip=buf.readLine();
Runtime H=Runtime.getRuntime();
Process p=H.exec("ping "+ip);
InputStream in=p.getInputStream();
BufferedReader buf1=new BufferedReader(new InputStreamReader(in));
while((str=buf1.readLine())!=null)
{System.out.println(str);
}}
catch(Exception e)
{System.out.println(e.getMessage());}
}
}
Output:
Program:
import java.io.*;
import java.net.*;
import java.util.*;
class ping
{
public static void main(String ar[]) throws Exception
{
try{
String str;
BufferedReader buf=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the ip address");
String ip=buf.readLine();
Runtime H=Runtime.getRuntime();
Process p=H.exec("ping "+ip);
InputStream in=p.getInputStream();
BufferedReader buf1=new BufferedReader(new InputStreamReader(in));
while((str=buf1.readLine())!=null)
{System.out.println(str);
}}
catch(Exception e)
{System.out.println(e.getMessage());}
}
}
Output:
0 comments:
Post a Comment