javaIP传入校验1个或多个H切割

 
	//ip传入单个或者多个校验  如127.0.0.1H127.168.0.0

public static boolean LotteryIP(String ip){
		Boolean bool=false;
		//对于通过多个代理的情况,
		if(ip!=null && ip.length()>15){ //"***.***.***.***".length() = 15

			String[] str = ip.split("H");
			String regex1="^(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|[1-9])\\."+
							"(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\."+
							"(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\."+
							"(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)$";
                        for (String ipstr: str){
                            if(ipstr.matches(regex1)){
                                bool=true;
                            }else{
                                bool=false;
                                return bool;
                            }
                        }
                        return bool;
		}
		if (ip!=null  ){//单个情况
			String regex2="^(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|[1-9])\\."+
							"(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\."+
							"(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\."+
							"(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)$";
                        if(ip.matches(regex2)){
                            bool=true;
                        }else{
                            bool=false;
                            return bool;
                        }
		}
                return bool;
	}

 

你可能感兴趣的:(模板)