c#中获取本机所有的IPv6地址
2007-03-01 09:50
274 查看
需要使用命名空间:using System.Net.NetworkInformation;
下述代码中,textBox2是一文本框,用于显示每个接口的描述字串,ipListComb是一组合列表框,存放所获得的IP地址.
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);
}
}
}
}
下述代码中,textBox2是一文本框,用于显示每个接口的描述字串,ipListComb是一组合列表框,存放所获得的IP地址.
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);
}
}
}
}
相关文章推荐
- C# GetSchema Get List of Table 获取数据库中所有的表名以及表中的纪录条数的方法
- C# 获取两个时间段之间的所有时间与获取当前时间所在的季度开始和结束时间
- C#学习笔记(21)——C#获取文件夹下的所有文件的文件名
- .net/c# memcached 获取所有缓存键(keys)
- C#获取文件夹下的所有文件的文件名
- 采肜c#获取数据库中的所有表
- .net/c# memcached缓存获取所有缓存键的方法步骤
- C#及WPF获取本机所有字体和颜色的方法
- C#获取oracle中某个用户的所有表
- C# 获取Access数据库中所有的表名
- C#下获取本地计算机的所有IP地址
- C#获取文件夹下的所有文件名
- C#获取远程网页中的所有链接URL
- C#获取远程网页中的所有链接URL(网络蜘蛛实现原理)
- [c#]获取数据库中所有表的表名
- c#获取数据库中所有表名称的方法
- c#获取数据库中所有表名称的方法
- C#获取“所有用户桌面”的路径
- C#获取远程网页中的所有链接URL(网络蜘蛛实现原理)
- c# 获取所有网卡的信息(IP。MAC)