以下是我在 Windows XP 中获取默认 NIC 的代码,但相同的代码在 Windows 7 中不起作用。阅读 MSDN 后确实令人困惑。有什么解决办法吗?
//----------------- Getting all the Nic's --------------------
foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
{
//------------ Getting properties of IPV4 ----------------
IPInterfaceProperties ipProps = nic.GetIPProperties();
//------------ Getting the Ip Properties -----------------
if (ipProps.GetIPv4Properties() != null)
{
dic.Add(ipProps.GetIPv4Properties().Index, nic.Name);
}
错误:请求协议(protocol)未配置,或没有实现。
最佳答案
这意味着您正在访问不支持 IPv4 的接口(interface)。 检查它:
if (nic.Supports(NetworkInterfaceComponent.IPv4)) // means IPv4 support is present
参见 here了解更多。
关于c# - Windows 7 默认网络适配器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14112815/