import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Ping {
/**
* 方法名稱 :ping
* 創 建 人:wumanxin
* 功能說明 :連接主機
* @return 返回連接的狀態
*/
public static boolean ping(String ipAddress) throws Exception {
int timeOut = 3000 ; //超時應該在3鈔以上
boolean status = InetAddress.getByName(ipAddress).isReachable(timeOut); // 當返回值是true時,說明host是可用的,false則不可。
return status;
}
/**
* 方法名稱 :main
* 創 建 人:wumanxin
* 功能說明 :用於測試是否可以ping通
* @return
*/
public static void main(String[] args) throws Exception {
String ipAddress = "www.baidu.com";
System.out.println(ping(ipAddress));
}
}