/** * Creates a {@link IPRange} instance by IP with mask. * * @param ipWithMask IP/mask, such as 192.168.70.1/24 * @return {@link IPRange} instance */ public static IPRange parseFromIPWithMask(String ipWithMask) { long minIpAsLong = 0; long maxIpAsLong = 0; String[] strs = ipWithMask.split("/"); if (strs.length == 2) { IP ip = IP.parseFromString(strs[0]); int mask = Integer.parseInt(strs[1]); long maskAsLong = 0xffffffff << (32 - mask); minIpAsLong = ip.toLong(); maxIpAsLong = minIpAsLong | (~maskAsLong); } else { throw new IllegalArgumentException( "The input String format error. for example" + " 192.168.1.1/24"); } return new IPRange(new IP(minIpAsLong), new IP(maxIpAsLong)); }