static public function NormalizeIPv6Address($ipv6)
    {

        if (strpos($ipv6, "::") === false && substr_count($ipv6, ":") !== 7) {
            throw new \Exception("Invalid IPv6 address");
        }

        if (strpos($ipv6, "::") !== false) {

            $padding = ":";

            $paddingRequired = 9 - substr_count($ipv6, ":");

            while (substr_count($padding, ":") < $paddingRequired) {

                $padding .= "0000:";

            }

            $ipv6 = str_replace("::", $padding, $ipv6);
        }

        $ipv6 = explode(":", $ipv6);

        foreach ($ipv6 as &$field) {

            while (strlen($field) < 4) {

                $field = "0{$field}";

            }

        }

        return implode(":", $ipv6);

    }