Ping a domain name using java code

by Vinoth 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);
}
}
}

Tagged in:

1566
like
0
dislike
0
mail
flag

You must LOGIN to add comments