2013-01-01 72 views
3

以下是我在Windows XP中获取默认网卡的代码,但是相同的代码在Windows 7中无法使用。阅读MSDN后真的让人感到困惑。任何解决方案Windows 7默认网络适配器

//----------------- 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); 
    } 

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

+0

哪一行是你得到的错误? –

回答

2

这意味着你正在接触没有IPv4支持的接口。 检查它:

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

更多见here

+0

Genious ...................... –

相关问题