Explorar el Código

Add support for validation of IPv6 addresses

olegkap_cp hace 14 años
padre
commit
be0dbf600e
Se han modificado 1 ficheros con 9 adiciones y 1 borrados
  1. 9 1
      Renci.SshClient/Renci.SshNet/Common/Extensions.cs

+ 9 - 1
Renci.SshClient/Renci.SshNet/Common/Extensions.cs

@@ -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)