Add support for validation of IPv6 addresses

This commit is contained in:
olegkap_cp
2011-06-13 13:46:09 +00:00
parent 2bea9352eb
commit be0dbf600e
@@ -168,13 +168,21 @@ namespace Renci.SshNet
}
private static Regex _rehost = new Regex(@"^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$|^(([a-zA-Z]|[a-zA-Z][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z]|[A-Za-z][A-Za-z0-9\-]*[A-Za-z0-9])$", RegexOptions.IgnoreCase | RegexOptions.Compiled);
private static Regex _reIPv6 = new Regex(@"^(((?=(?>.*?::)(?!.*::)))(::)?([0-9A-F]{1,4}::?){0,5}|([0-9A-F]{1,4}:){6})(\2([0-9A-F]{1,4}(::?|$)){0,2}|((25[0-5]|(2[0-4]|1\d|[1-9])?\d)(\.|$)){4}|[0-9A-F]{1,4}:[0-9A-F]{1,4})(?<![^:]:|\.)\z", RegexOptions.IgnoreCase | RegexOptions.Compiled);
internal static bool IsValidHost(this string value)
{
if (value == null)
return false;
return _rehost.Match(value).Success;
if (_rehost.Match(value).Success)
return true;
if (_reIPv6.Match(value).Success)
return true;
return false;
}
internal static bool IsValidPort(this uint value)