[C#]取得網卡的IPV6位置
namespace ConsoleApplication13 { class Program { static void Main(string[] args) { foreach (var ip in GetLocalIPV6IP()) { Console.WriteLine(ip); } }
private static IEnumerable<String> GetLocalIPV6IP()
{
return (from adapter in NetworkInterface.GetAllNetworkInterfaces()
where adapter .NetworkInterfaceType == NetworkInterfaceType.Ethernet
from AddressInfo in adapter.GetIPProperties().UnicastAddresses.OfType<UnicastIPAddressInformation>()
where AddressInfo.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6
let ipAddress = AddressInfo.Address.ToString()
select ipAddress);
}
}
}