我想使用 System.Net.IPAddress.TryParse 来验证 IPv6 地址,因为我不想编写自己的 reg exp :-)
但是,这似乎允许诸如“(validIPv6)](anythingatallhere)”之类的字符串 - 例如,“1234::5678:abcd]whargarbl”。
这些是否有效,或者这是一个错误?
由于我实际上只想要 "[(validIPv6)]:(portnumber)" 形式的字符串,因此我将不得不自己做一些验证。
我想使用 System.Net.IPAddress.TryParse 来验证 IPv6 地址,因为我不想编写自己的 reg exp :-)
但是,这似乎允许诸如“(validIPv6)](anythingatallhere)”之类的字符串 - 例如,“1234::5678:abcd]whargarbl”。
这些是否有效,或者这是一个错误?
由于我实际上只想要 "[(validIPv6)]:(portnumber)" 形式的字符串,因此我将不得不自己做一些验证。
I was looking through reflector and it seems that if your current OS does not support IPV6 a parse routine is called that will ignore everything past the final ']'
character.
This here seems to be the offending code, take notice of the second or condition as it relates to the preceding bit of code.
int length = ipString.Length;
fixed (char* str2 = ((char*) ipString))
{
char* name = str2;
if (IPv6AddressHelper.IsValid(name, start, ref length) || (length != ipString.Length))