- IP v4 校验
public static boolean isboolIp(String ipAddress) {
String ip = "([1-9]|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])(\\.(\\d|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])){3}";
Pattern pattern = Pattern.compile(ip);
Matcher matcher = pattern.matcher(ipAddress);
return matcher.matches();
}
2.IP v6 校验
public static void isboolIpv6(String ipAddress) {标签:ip,IP,Java,String,9a,Ip,正则,matcher,ipAddress From: https://blog.51cto.com/u_15948835/6049666
String re = "^([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$";
return ipAddress.matches(re);
}