这是测试代码:
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
public class TestPing {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String host = "www.baidu.com";
int timeOut = 3000;
try {
boolean statu = InetAddress.getByName(host).isReachable(timeOut);
System.out.println(statu);
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}