package com.bocloud.ims.common.utils;

import java.util.regex.Pattern;

/**
 * IP验证器
 *
 * @author sxp
 * @since 2023/7/4
 */
public class IpValidator {
	/**
	 * IPv4地址的正则表达式匹配模式
	 * <p>
	 * xxx.xxx.xxx.xxx <br>
	 * xxx的取值范围是:0~255
	 * </p>
	 */
	private static final Pattern IP_PATTERN = Pattern
			.compile("((2[0-4]\\d|25[0-5]|[01]?\\d\\d?)\\.){3}(2[0-4]\\d|25[0-5]|[01]?\\d\\d?)");

	/**
	 * 检验IPv4地址的合法性
	 *
	 * @author sxp
	 * @since 2023/7/4
	 */
	public static boolean isValidIPv4(String ip) {
		if (ip == null) {
			return false;
		}
		return IP_PATTERN.matcher(ip).matches();
	}
}
