Windows 7默认网络适配器

时间:2013-01-01 17:58:47

标签: c# .net

以下是我在Windows XP中获取默认网卡的代码,但相同的代码在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);
    }

错误:未配置请求协议,或者没有实现。

1 个答案:

答案 0 :(得分:2)

这意味着您在没有IPv4支持的情况下访问界面。 检查它:

if (nic.Supports(NetworkInterfaceComponent.IPv4)) // means IPv4 support is present

有关详情,请参阅here