Ping a domain name using java code
by Vinoth[ Edit ] 2010-01-28 19:35:18
import java.net.*;
import java.io.*;
import java.util.*;
class pingTest {
public static void main(String[] args) {
String ip = args[0];
String pingResult = "";
String pingCmd = "ping " + ip;
try {
Runtime r = Runtime.getRuntime();
Process p = r.exec(pingCmd);
BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null) {
System.out.println(inputLine);
pingResult += inputLine;
}
in.close();
}
catch (IOException e) {
System.out.println(e);
}
}
}