All Downloads are FREE. Search and download functionalities are using the official Maven repository.

myaction.utils.IPMask Maven / Gradle / Ivy

package myaction.utils;

public class IPMask {
	private long ipNet = 0;
	private long ipMask = 0; //初始化时,会做位翻转。即,默认为: 255.255.255.255
	
	private IPMask() {
	}
	
	/**
	 * 解析IP地址
	 * @param ipNet
	 * @return 解析失败,返回null。成功返回 IPMask 对象
	 */
	public static IPMask parse(String ipNet) {
		if(ipNet == null) {
			return null;
		}
		ipNet = ipNet.trim();
		String[] arr = StringUtil.split(ipNet, '/');
		long ipNum = convertIP(arr[0]);
		if(ipNum < 0) {
			return null;
		}
		int maskLen = 32;
		if(arr.length > 1) {
			maskLen = MathUtil.parseInt(arr[1]);
			maskLen = Math.max(0, maskLen);
			maskLen = Math.min(32, maskLen);
		}
		IPMask mask = new IPMask();
		maskLen = 32 - maskLen; //反转
		for(int i=0; i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy