我希望你能翻译如何获取所有网络接口的IPv4地址。 或者只需无线和以太网。
要获取所有网络接口的详细信息,我使用以下命令:
foreach (NetworkInterface ni in NetworkInterface.GetAllNetworkInterfaces()) {
if(ni.NetworkInterfaceType == NetworkInterfaceType.Wireless80211 ||
ni.NetworkInterfaceType == NetworkInterfaceType.Ethernet) {
Console.WriteLine(ni.Name);
}
}
要获取计算机的所有托管IPv4地址:
IPAddress [] IPS = Dns.GetHostAddresses(Dns.GetHostName());
foreach (IPAddress ip in IPS) {
if (ip.AddressFamily == AddressFamily.InterNetwork) {
Console.WriteLine("IP address: " + ip);
}
}
但是如何获取网络接口及其正确的IPv4地址?