public static boolean isIp6InRange(final String ip6, final String ip6Range) { if (ip6Range == null) { return false; } final String[] ips = ip6Range.split("-"); final String startIp = ips[0]; String endIp = null; if (ips.length > 1) { endIp = ips[1]; } final IPv6Address start = IPv6Address.fromString(startIp); final IPv6Address end = IPv6Address.fromString(endIp); final IPv6Address ip = IPv6Address.fromString(ip6); if (start.compareTo(ip) <= 0 && end.compareTo(ip) >= 0) { return true; } return false; }
IPv6Address start = IPv6Address.fromString(startIp); IPv6Address end = IPv6Address.fromString(endIp); if (end.compareTo(start) < 0) { return false; if (gateway.compareTo(start) == 0 || gateway.compareTo(end) == 0) { return false; if (network.getFirst().compareTo(start) == 0) { return false; if (network.getLast().compareTo(end) == 0) { return false;
public static List<String> getFreeIpv6InRange(String startIp, String endIp, List<String> usedIps, int limit, String start) { IPv6Address s = IPv6Address.fromString(startIp); IPv6Address e = IPv6Address.fromString(endIp); IPv6Address f = IPv6Address.fromString(start); IPv6AddressRange range = IPv6AddressRange.fromFirstAndLast(s, e); List<String> res = new ArrayList<String>(); while (s.compareTo(e) <= 0) { if (s.compareTo(f) <= 0) { s = s.add(1); continue; } if (usedIps.contains(s.toString())) { s = s.add(1); continue; } res.add(s.toString()); s = s.add(1); if (res.size() >= limit) { break; } } return res; }
@Override public boolean hasNext() { // there is a next subnet as long as we didn't reach the end of the range return base != null && (base.compareTo(last) <= 0); }
@Override public boolean hasNext() { return current.compareTo(last) <= 0; }
@Override public boolean hasNext() { // there is a next subnet as long as we didn't reach the end of the range return base != null && (base.compareTo(last) <= 0); }
@Override public boolean hasNext() { return current.compareTo(last) <= 0; }
IPv6AddressRange(IPv6Address first, IPv6Address last) { if (first.compareTo(last) > 0) throw new IllegalArgumentException("Cannot create ip address range with last address < first address"); this.first = first; this.last = last; }
IPv6AddressRange(IPv6Address first, IPv6Address last) { if (first.compareTo(last) > 0) throw new IllegalArgumentException("Cannot create ip address range with last address < first address"); this.first = first; this.last = last; }
/** * The natural order of {@link com.googlecode.ipv6.IPv6AddressRange}s orders them on increasing first addresses, and on increasing last * address if the first address would be equal. * <p> * Note that the natural order does thus not compare sizes of ranges. * * @param that range to compare with * @return negative, zero or positive depending on whether this is smaller, equal or greater than that */ @Override public int compareTo(IPv6AddressRange that) { if (!this.first.equals(that.first)) return this.first.compareTo(that.first); else return this.last.compareTo(that.last); }
/** * Extend the range just enough at its head or tail such that the given address is included. * * @param address address to extend the range to * @return new (bigger) range */ public IPv6AddressRange extend(IPv6Address address) { if (address.compareTo(first) < 0) return fromFirstAndLast(address, last); else if (address.compareTo(last) > 0) return fromFirstAndLast(first, address); else return this; }
/** * Extend the range just enough at its head or tail such that the given address is included. * * @param address address to extend the range to * @return new (bigger) range */ public IPv6AddressRange extend(IPv6Address address) { if (address.compareTo(first) < 0) return fromFirstAndLast(address, last); else if (address.compareTo(last) > 0) return fromFirstAndLast(first, address); else return this; }
public static boolean isIp6InRange(final String ip6, final String ip6Range) { if (ip6Range == null) { return false; } final String[] ips = ip6Range.split("-"); final String startIp = ips[0]; String endIp = null; if (ips.length > 1) { endIp = ips[1]; } final IPv6Address start = IPv6Address.fromString(startIp); final IPv6Address end = IPv6Address.fromString(endIp); final IPv6Address ip = IPv6Address.fromString(ip6); if (start.compareTo(ip) <= 0 && end.compareTo(ip) >= 0) { return true; } return false; }
@Override public boolean hasNext() { return current.getLast().compareTo(IPv6Network.this.getLast()) <= 0; }
@Override public boolean hasNext() { return current.getLast().compareTo(IPv6Network.this.getLast()) <= 0; }
public static boolean isIp6InNetwork(final String ip6, final String ip6Cidr, final Boolean inclusiveHostCount) { IPv6Network network = null; try { network = IPv6Network.fromString(ip6Cidr); } catch (final IllegalArgumentException ex) { return false; } final IPv6Address ip = IPv6Address.fromString(ip6); if (inclusiveHostCount) { return network.contains(ip); } else { return ((network.getFirst().compareTo(ip) < 0) && (network.getLast().compareTo(ip) > 0)); } }