Validates an IPv6 address. Returns true if valid.
@param inet6Address the IPv6 address to validate
@return true if the argument contains a valid IPv6 address

@since 1.4.1
185865
public boolean isValidInet6Address(String inet6Address) {
        boolean containsCompressedZeroes = inet6Address.contains("::");
        if (containsCompressedZeroes && (inet6Address.indexOf("::") != inet6Address.lastIndexOf("::"))) {
            return false;
        }
        if ((inet6Address.startsWith(":") && !inet6Address.startsWith("::"))
                || (inet6Address.endsWith(":") && !inet6Address.endsWith("::"))) {
            return false;
        }
        String[] octets = inet6Address.split(":");
        if (containsCompressedZeroes) {
            List<String> octetList = new ArrayList<>(Arrays.asList(octets));
            if (inet6Address.endsWith("::")) {
                // String.split() drops ending empty segments
                octetList.add("");
            } else if (inet6Address.startsWith("::") && !octetList.isEmpty()) {
                octetList.remove(0);
            }
            octets = octetList.toArray(new String[0]);
        }
        if (octets.length > IPV6_MAX_HEX_GROUPS) {
            return false;
        }
        int validOctets = 0;
        int emptyOctets = 0; // consecutive empty chunks
        for (int index = 0; index < octets.length; index++) {
            String octet = octets[index];
            if (octet.length() == 0) {
                emptyOctets++;
                if (emptyOctets > 1) {
                    return false;
                }
            } else {
                emptyOctets = 0;
                // Is last chunk an IPv4 address?
                if (index == octets.length - 1 && octet.contains(".")) {
                    if (!isValidInet4Address(octet)) {
                        return false;
                    }
                    validOctets += 2;
                    continue;
                }
                if (octet.length() > IPV6_MAX_HEX_DIGITS_PER_GROUP) {
                    return false;
                }
                int octetInt = 0;
                try {
                    octetInt = Integer.parseInt(octet, BASE_16);
                } catch (NumberFormatException e) {
                    return false;
                }
                if (octetInt < 0 || octetInt > MAX_UNSIGNED_SHORT) {
                    return false;
                }
            }
            validOctets++;
        }
        if (validOctets > IPV6_MAX_HEX_GROUPS || (validOctets < IPV6_MAX_HEX_GROUPS && !containsCompressedZeroes)) {
            return false;
        }
        return true;
    }
811428
public static function ipAddress($ipAddress)
    {
        if (false === filter_var($ipAddress, FILTER_VALIDATE_IP)) {
            throw new InputValidationException('invalid "ip_address"');
        }

        // normalize the IP address (only makes a difference for IPv6)
        return inet_ntop(inet_pton($ipAddress));
    }
234735
public function ipValidateV6($ip)
    {
        $this->debug->info(__FUNCTION__, 'IP: ' . json_encode($ip));
        if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) === FALSE) {
            $this->debug->info(__FUNCTION__, 'Valid is FALSE');

            return FALSE;
        }

        $this->debug->info(__FUNCTION__, 'Valid is TRUE');

        return TRUE;
    }
1023047
public boolean isIPAddressInRange(IPAddress address) {
		if (ipSubnetMask == null) {
			return this.ipAddress.equals(address);
		}
		
		int result1 = address.getIPAddress() & ipSubnetMask.getIPAddress();
		int result2 = ipAddress.getIPAddress() & ipSubnetMask.getIPAddress();
		
		return result1 == result2;
	}
1184784
private static boolean useInetAddress(NetworkInterface networkInterface, InetAddress interfaceAddress) {
        return checkMethod(networkInterface, isUp) &&
               checkMethod(networkInterface, supportsMulticast) &&
               // TODO: IpV6 support
               !(interfaceAddress instanceof Inet6Address) &&
               !interfaceAddress.isLoopbackAddress();
    }
581171
public static void validateAddress(String address) {
		// Check for improperly formatted addresses
		Matcher matcher = ADDRESS_PATTERN.matcher(address);
		if(!matcher.matches()) {
			String message = "The address must have the format X.X.X.X";
			throw new IllegalArgumentException(message);
		}

		// Check for out of range address components
		for(int i = 1; i <= 4; i++) {
			int component = Integer.parseInt(matcher.group(i));
			if(component < 0 || component > 255) {
				String message = "All address components must be in the range [0, 255]";
				throw new IllegalArgumentException(message);
			}
		}
	}
493058
public function validateIpAddress(string $ipAddress) : bool
    {
        if ($ipAddress === '') {
            return false;
        }

        return (bool) filter_var($ipAddress, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE);
    }
1347473
private static boolean isIPv4MappedAddress(final byte[] addr) {
    if (addr.length < INADDR16SZ) {
      return false;
    }
    return addr[0] == 0x00 && addr[1] == 0x00 && addr[2] == 0x00 && addr[3] == 0x00
        && addr[4] == 0x00 && addr[5] == 0x00 && addr[6] == 0x00 && addr[7] == 0x00
        && addr[8] == 0x00 && addr[9] == 0x00 && addr[10] == (byte) 0xff && addr[11] == (byte) 0xff;
  }
461953
@Nullable
    static byte[] ipv6ToIpv4Address(Inet6Address address) {
        final byte[] addr = address.getAddress();
        assert addr.length == 16
                : "the length of " + address.getClass().getSimpleName() + ": " + addr.length;
        // The first 10 bytes should be 0.
        for (int i = 0; i < 10; i++) {
            if (addr[i] != 0x00) {
                return null;
            }
        }

        if (addr[10] == 0x00 && addr[11] == 0x00) {
            if (addr[12] == 0x00 && addr[13] == 0x00 && addr[14] == 0x00 && addr[15] == 0x01) {
                return localhost;
            }
            return new byte[] { addr[12], addr[13], addr[14], addr[15] };
        }

        if (addr[10] == (byte) 0xFF && addr[11] == (byte) 0xFF) {
            return new byte[] { addr[12], addr[13], addr[14], addr[15] };
        }

        return null;
    }
512548
public static boolean isValidArg(String arg) {
    final String[] args = arg.split(":");
    if (args.length != 2) {
      return false;
    }

    final String ip = args[1];
    return InetAddresses.isInetAddress(ip);
  }
1153218
public static Inet4Address anonymizeIpV4Address(Inet4Address inetAddress) {
		try {
			final byte[] address = inetAddress.getAddress();
			anonymizeLastBytes(address, ANONYMIZED_IPV4_OCTETS);
			return (Inet4Address) InetAddress.getByAddress(address);
		} catch (UnknownHostException e) {
			throw new AssertionError(e);
		}
	}
535192
public static boolean isInetAddress(String host) {
		int colons = 0;
		int dots = 0;
		byte[] bytes = encodeAscii(host);

		// expect ipv6 address
		if (bytes[0] == '[') {
			return bytes[bytes.length - 1] == ']' && checkIpv6(bytes, 1, bytes.length - 1);
		}

		// assume ipv4 could be as oct, bin, dec; ipv6 - hex
		for (byte b : bytes) {
			if (b == '.') {
				dots++;
			} else if (b == ':') {
				if (dots != 0) {
					return false;
				}
				colons++;
			} else if (Character.digit(b, 16) == -1) {
				return false;
			}
		}

		if (dots < 4) {
			if (colons > 0 && colons < 8) {
				return checkIpv6(bytes, 0, bytes.length);
			}
			return checkIpv4(bytes, 0, bytes.length);
		}
		return false;
	}
61959
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;
    }
497237
def is_valid_ip(ip_address):
    
    if not ip_address:
        return False
    ip_address = ip_address.strip()
    try:
        validate_ipv46_address(ip_address)
        return True
    except ValidationError:
        return False
1186034
@Trivial
    public static boolean validLocalHostName(String hostName) {
        InetAddress addr = findLocalHostAddress(hostName, PREFER_IPV6);
        return addr != null;
    }
1305590
static byte[] inet6AsByteArray(InetAddress ia) {
        if (ia instanceof Inet6Address) {
            return ia.getAddress();
        }

        // need to construct IPv4-mapped address
        if (ia instanceof Inet4Address) {
            byte[] ip4address = ia.getAddress();
            byte[] address = new byte[16];
            address[10] = (byte)0xff;
            address[11] = (byte)0xff;
            address[12] = ip4address[0];
            address[13] = ip4address[1];
            address[14] = ip4address[2];
            address[15] = ip4address[3];
            return address;
        }

        throw new AssertionError("Should not reach here");
    }
499295
def check_ipv6(ip_str):
    

    try:
        socket.inet_pton(socket.AF_INET6, ip_str)
    except socket.error:
        return False
    return True