Exemplo n.º 1
0
 public static int getIp6CidrSize(String ip6Cidr) {
   IPv6Network network = null;
   try {
     network = IPv6Network.fromString(ip6Cidr);
   } catch (IllegalArgumentException ex) {
     return 0;
   }
   return network.getNetmask().asPrefixLength();
 }
Exemplo n.º 2
0
 public static boolean isIp6InNetwork(String ip6, String ip6Cidr) {
   IPv6Network network = null;
   try {
     network = IPv6Network.fromString(ip6Cidr);
   } catch (IllegalArgumentException ex) {
     return false;
   }
   IPv6Address ip = IPv6Address.fromString(ip6);
   return network.contains(ip);
 }
Exemplo n.º 3
0
 /**
  * parse IPV6 ARPA domain to IP bytes.
  *
  * @param name an ARPA string.
  * @return ARPA.
  */
 private static NetworkInBytes parseIpV6Arpa(String name) {
   LOGGER.debug("parseIp6Arpa, name:" + name);
   String arpa = StringUtils.removeEndIgnoreCase(name, CHAR_DOT + DomainUtil.IPV6_ARPA_SUFFIX);
   arpa = StringUtils.remove(arpa, CHAR_DOT);
   String ip = StringUtils.reverse(arpa);
   String fullIp = StringUtils.rightPad(ip, 32, '0');
   byte[] startIpBytes = DatatypeConverter.parseHexBinary(fullIp);
   int networkMask = StringUtils.length(arpa) * 4;
   IPv6Address fromByteArray = IPv6Address.fromByteArray(startIpBytes);
   IPv6Network network =
       IPv6Network.fromAddressAndMask(
           fromByteArray, IPv6NetworkMask.fromPrefixLength(networkMask));
   NetworkInBytes result =
       new NetworkInBytes(
           IpVersion.V6, network.getFirst().toByteArray(), network.getLast().toByteArray());
   return result;
 }
Exemplo n.º 4
0
 public static boolean isValidIp6Cidr(String ip6Cidr) {
   try {
     IPv6Network network = IPv6Network.fromString(ip6Cidr);
   } catch (IllegalArgumentException ex) {
     return false;
   }
   return true;
 }