/**
* 判断所有的IP地址
* @param IP
* @return
*/
public String validIPAddressAll(String IP) {
if (!IP.contains(".") && !IP.contains(":")) {
return "Neither";
}
//如果是IPV4
if (IP.contains(".")) {
if (IP.endsWith(".")) {
return "Neither";
}
String[] arr = IP.split("\\.");
if (arr.length != 4) {
return "Neither";
}
for (int i = 0; i < 4; i++) {
if (arr[i].length() == 0 || arr[i].length() > 3) {
return "Neither";
java 判断IP地址是否合法,是IPV4,还是IPV6
最新推荐文章于 2024-04-26 10:49:17 发布