1.导入hutool的maven依赖
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.8.16</version>
</dependency>
2.直接复制一下代码
import cn.hutool.core.lang.Validator;
public class Test {
public static void main(String[] args) throws Exception{
String ip = "192.168.0.1";
if (Validator.isIpv4(ip) || Validator.isIpv6(ip)) {
System.out.println("ip地址正确");
}else {
System.out.println("ip地址有误");
}
}
}
标签:java,cn,ip,hutool,地址,Validator,String
From: https://blog.csdn.net/qq_43700885/article/details/140768409