/** * 校验ip是否符合IPV4格式和IPV6格式 * <p> * Title: validate_ip * </p> * <p> * Description:校验ip是否符合IPV4格式和IPV6格式 * </p> * * @param ip * IP地址 * @return true|false true:符合, false :不符合 */ public static boolean validate_IPV4OrIPV6(String ip) { InetAddress addressIp = null; if (null == ip || "".equals(ip.trim())) { return false; } try { addressIp = InetAddress.getByName(ip); } catch (UnknownHostException e) { return false; } if (addressIp instanceof Inet4Address || addressIp instanceof Inet6Address) { return true; } return false; }
乐享:知识积累,快乐无限。