/** * Returns true if the given IPv4 address is in the specific Ipv4 range */ public static boolean isIpInRange(final String ipInRange, final String startIP, final String endIP) { if (ipInRange == null || !validIpRange(startIP, endIP)) return false; final long ipInRangeLong = NetUtils.ip2Long(ipInRange); final long startIPLong = NetUtils.ip2Long(startIP); final long endIPLong = NetUtils.ip2Long(endIP); return startIPLong <= ipInRangeLong && ipInRangeLong <= endIPLong; }
private void validateRemoteAccessVpnConfiguration() throws ConfigurationException { String ipRange = RemoteAccessVpnClientIpRange.value(); if (ipRange == null) { s_logger.warn("Remote Access VPN global configuration missing client ip range -- ignoring"); return; } Integer pskLength = _pskLength; if (pskLength != null && (pskLength < 8 || pskLength > 256)) { throw new ConfigurationException("Remote Access VPN: IPSec preshared key length should be between 8 and 256"); } String[] range = ipRange.split("-"); if (range.length != 2) { throw new ConfigurationException("Remote Access VPN: Invalid ip range " + ipRange); } if (!NetUtils.isValidIp4(range[0]) || !NetUtils.isValidIp4(range[1])) { throw new ConfigurationException("Remote Access VPN: Invalid ip in range specification " + ipRange); } if (!NetUtils.validIpRange(range[0], range[1])) { throw new ConfigurationException("Remote Access VPN: Invalid ip range " + ipRange); } }
public static Boolean validIpRangeList(final String ipRangeList) { if (StringUtils.isEmpty(ipRangeList)) { return false; } final String[] ipRanges = ipRangeList.split(","); for (final String ipRange : ipRanges) { if (!(ipRange.contains("-") && validIpRange(ipRange) || isValidIp4(ipRange))) { return false; } } return true; } }
if (endIP != null && !NetUtils.validIpRange(startIP, endIP)) { throw new InvalidParameterValueException("Please specify a valid IP range.");
public static boolean validIpRange(final String ipRange) { if (StringUtils.isEmpty(ipRange)) { return false; } final String[] ipAddresses = ipRange.split("-"); return (ipAddresses.length == 2) && isValidIp4(ipAddresses[0]) && isValidIp4(ipAddresses[1]) && validIpRange(ipAddresses[0], ipAddresses[1]); }
if (!NetUtils.isValidIp4(startIP) || !NetUtils.isValidIp4(endIP) || !NetUtils.validIpRange(startIP, endIP)) { throw new InvalidParameterValueException("Invalid portable ip range: " + startIP + "-" + endIP);
throw new InvalidParameterValueException("Invalid ip in range specification " + ipRange); if (!NetUtils.validIpRange(range[0], range[1])) { throw new InvalidParameterValueException("Invalid ip range " + ipRange);