gpt4 book ai didi

c# - Windows 7 默认网络适配器

转载 作者:行者123 更新时间:2023-11-30 17:07:57 26 4
gpt4 key购买 nike

以下是我在 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com