*.下载:微软IPv6技术白皮书
*.下述代码是列出所有的单播IPv6地址.
private void DisplayAllAddresses()
{
NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();
int i=0;
foreach (NetworkInterface adapter in adapters)
{
IPInterfaceProperties adapterProperties = adapter.GetIPProperties();
UnicastIPAddressInformationCollection allAddress =
adapterProperties.UnicastAddresses;
if (allAddress.Count > 0)
{
textBox2.Text += "interface "+i+ "description:/n/t "+adapter.Description+ "/n ";
i++;
foreach (UnicastIPAddressInformation addr in allAddress)
{
if (addr.Address.AddressFamily ==AddressFamily.InterNetworkV6)
ipListComb.Items.Add(addr.Address);
}
}
}
}
*.判断输入的字符串是否是合法的IPV6 地址
public static bool IsIPV6(string input)
{
string pattern = "";
string temp = input;
string[] strs = temp.Split(':');
if(strs.Length > 8)
{
return false;
}
int count = MetarnetRegex.GetStringCount(input,"::");
if(count>1)
{
return false;
}
else if(count == 0)
{
pattern = @"^([/da-f]{1,4}:){7}[/da-f]{1,4}$";
Regex regex = new Regex(pattern);
return regex.IsMatch(input);
}
else
{
pattern = @"^([/da-f]{1,4}:){0,5}::([/da-f]{1,4}:){0,5}[/da-f]{1,4}$";
Regex regex1 = new Regex(pattern);
return regex1.IsMatch(input);
}
}
*.IPv6 and IPv4 Support in WMI
本文介绍了通过C#实现IPv6地址的获取与合法性验证的方法,包括如何利用.NET框架API来枚举系统上的所有IPv6单播地址,并提供了一种简单有效的方式检查一个字符串是否为合法的IPv6地址。
1970

被折叠的 条评论
为什么被折叠?



