2013-01-01 82 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 ...................... –

相關問題