Package com.googlecode.ipv6

Examples of com.googlecode.ipv6.IPv6AddressHelpers


        return true;
    }

  public static boolean isValidIpv6(String ip) {
    try {
      IPv6Address address = IPv6Address.fromString(ip);
    } catch (IllegalArgumentException ex) {
      return false;
    }
    return true;
  }
View Full Code Here


  // Can cover 127 bits
  public static String getIp6FromRange(String ip6Range) {
      String[] ips = ip6Range.split("-");
      String startIp = ips[0];
      IPv6Address start = IPv6Address.fromString(startIp);
      BigInteger gap = countIp6InRange(ip6Range);
      BigInteger next = new BigInteger(gap.bitLength(), _rand);
      while (next.compareTo(gap) >= 0) {
        next = new BigInteger(gap.bitLength(), _rand);
      }
      BigInteger startInt = convertIPv6AddressToBigInteger(start);
      BigInteger resultInt = startInt.add(next);
      InetAddress resultAddr;
    try {
      resultAddr = InetAddress.getByAddress(resultInt.toByteArray());
    } catch (UnknownHostException e) {
      return null;
    }
      IPv6Address ip = IPv6Address.fromInetAddress(resultAddr);
      return ip.toString();
  }
View Full Code Here

      String startIp = ips[0];
      String endIp = ips[0];
      if (ips.length > 1) {
        endIp = ips[1];
      }
      IPv6Address start, end;
      try {
        start = IPv6Address.fromString(startIp);
        end = IPv6Address.fromString(endIp);
    } catch (IllegalArgumentException ex) {
      return null;
View Full Code Here

      String startIp = ips[0];
      String endIp = null;
      if (ips.length > 1) {
        endIp = ips[1];
      }
      IPv6Address start = IPv6Address.fromString(startIp);
      IPv6Address end = IPv6Address.fromString(endIp);
      IPv6Address ip = IPv6Address.fromString(ip6);
      if (start.compareTo(ip) <= 0 && end.compareTo(ip) >= 0) {
        return true;
      }
    return false;
  }
View Full Code Here

    try {
      network = IPv6Network.fromString(ip6Cidr);
    } catch (IllegalArgumentException ex) {
      return false;
    }
      IPv6Address ip = IPv6Address.fromString(ip6);
    return network.contains(ip);
  }
View Full Code Here

      String startIp1 = ips[0];
      String endIp1 = null;
      if (ips.length > 1) {
        endIp1 = ips[1];
      }
      IPv6Address start1 = IPv6Address.fromString(startIp1);
      IPv6Address end1 = IPv6Address.fromString(endIp1);
      IPv6AddressRange range1 = IPv6AddressRange.fromFirstAndLast(start1, end1);
    ips = ipRange2.split("-");
      String startIp2 = ips[0];
      String endIp2 = null;
      if (ips.length > 1) {
        endIp2 = ips[1];
      }
      IPv6Address start2 = IPv6Address.fromString(startIp2);
      IPv6Address end2 = IPv6Address.fromString(endIp2);
      IPv6AddressRange range2 = IPv6AddressRange.fromFirstAndLast(start2, end2);
      return range1.overlaps(range2);
  }
View Full Code Here

      String startIp = ips[0];
      String endIp = null;
      if (ips.length > 1) {
        endIp = ips[1];
      }
      IPv6Address start = IPv6Address.fromString(startIp);
      IPv6Address end = IPv6Address.fromString(endIp);
      IPv6Address current = IPv6Address.fromString(currentIp);
      IPv6Address result = null;
      if (current.equals(end)) {
        result = start;
      } else{
        result = current.add(1);
      }
      String resultIp = null;
      if (result != null) {
        resultIp = result.toString();
      }
    return resultIp;
  }
View Full Code Here

        String ip = NetUtils.getIp6FromRange("1234:5678::1-1234:5678::2");
        assertTrue(ip.equals("1234:5678::1") || ip.equals("1234:5678::2"));
        s_logger.info("IP is " + ip);
      }
      String ipString = null;
      IPv6Address ipStart = IPv6Address.fromString("1234:5678::1");
      IPv6Address ipEnd = IPv6Address.fromString("1234:5678::ffff:ffff:ffff:ffff");
      for (int i = 0; i < 10; i ++) {
        ipString = NetUtils.getIp6FromRange(ipStart.toString() + "-" + ipEnd.toString());
        s_logger.info("IP is " + ipString);
        IPv6Address ip = IPv6Address.fromString(ipString);
        assertTrue(ip.compareTo(ipStart) >= 0);
        assertTrue(ip.compareTo(ipEnd) <= 0);
      }
      //Test isIp6RangeOverlap
      assertFalse(NetUtils.isIp6RangeOverlap("1234:5678::1-1234:5678::ffff", "1234:5678:1::1-1234:5678:1::ffff"));
      assertTrue(NetUtils.isIp6RangeOverlap("1234:5678::1-1234:5678::ffff", "1234:5678::2-1234:5678::f"));
      assertTrue(NetUtils.isIp6RangeOverlap("1234:5678::f-1234:5678::ffff", "1234:5678::2-1234:5678::f"));
View Full Code Here

        return true;
    }

    public static boolean isValidIpv6(String ip) {
        try {
            IPv6Address address = IPv6Address.fromString(ip);
        } catch (IllegalArgumentException ex) {
            return false;
        }
        return true;
    }
View Full Code Here

    // Can cover 127 bits
    public static String getIp6FromRange(String ip6Range) {
        String[] ips = ip6Range.split("-");
        String startIp = ips[0];
        IPv6Address start = IPv6Address.fromString(startIp);
        BigInteger gap = countIp6InRange(ip6Range);
        BigInteger next = new BigInteger(gap.bitLength(), _rand);
        while (next.compareTo(gap) >= 0) {
            next = new BigInteger(gap.bitLength(), _rand);
        }
        BigInteger startInt = convertIPv6AddressToBigInteger(start);
        BigInteger resultInt = startInt.add(next);
        InetAddress resultAddr;
        try {
            resultAddr = InetAddress.getByAddress(resultInt.toByteArray());
        } catch (UnknownHostException e) {
            return null;
        }
        IPv6Address ip = IPv6Address.fromInetAddress(resultAddr);
        return ip.toString();
    }
View Full Code Here

TOP

Related Classes of com.googlecode.ipv6.IPv6AddressHelpers

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.