mirror of
https://github.com/sshnet/SSH.NET.git
synced 2026-09-11 01:36:39 +00:00
Add support for validation of IPv6 addresses
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user