JAVA 中 验证IP的有效性

来源:互联网 发布:域名流量劫持 编辑:程序博客网 时间:2024/04/27 04:25
  public void pingIP(String ipKey, String ipValue) throws RSInstallerException{     
  Boolean bool=false;
  try
  {
   bool = InetAddress.getByName(ipValue.trim()).isReachable(10000);
  }
  catch (UnknownHostException e)
  {    
   throw new RSInstallerException(e.toString().split(":")[0],e.getMessage());
  }
  catch (IOException e)
  {   
   throw new RSInstallerException(e.toString().split(":")[0], e.getMessage());
  } 
 
  /*
   * If the IP can't ping record the detail info to log file
   */
  if (!bool)
  {
   String ipPingError = "The " + ipKey + " = " + ipValue + " ping failed .Maybe is the physics connection is illogical.";
   LOGGER.warn(ipPingError);
   warnInfo.append(ipPingError + "#");
  } 
 }
原创粉丝点击