class IpUtils {

  public static boolean isReachable(String ip) {
    if (!isValidIPv4(ip)) {
      return false;
    }

    boolean isReachable;

    try {
      InetAddress address = InetAddress.getByName(ip);
      int timeout = 2000;// 2秒超时时间

      logger.info("正在测试IP地址[" + ip + "]的连通性...");

      isReachable = address.isReachable(timeout);

    } catch (Exception e) {
      isReachable = false;
      logger.info("IP地址[" + ip + "]无法联通", e);
    }

    return isReachable;
  }

}