2009-07-04 122 views
2

我們的應用程序使用RSS從互聯網上下載數據,但在連接3G的計算機上發生連接問題。我們希望檢測3G,EDGE,GPRS連接,以便我們改變應用行爲,顯示警告或連接狀態。在.NET中檢測3G網絡連接

這將如何完成?

回答

2

NetworkInterface類的System.Net.NetworkInformation命名空間應該是一些使用你(更具體的,該GetAllNetworkInterfaces方法。一個例子顯示,演示瞭如何獲取類型,地址,工作狀態鏈接MSDN頁面上,和其他對每個網絡接口信息

MSDN例子的簡化版本:

public static void ShowNetworkInterfaces() 
{ 
    IPGlobalProperties computerProperties = IPGlobalProperties.GetIPGlobalProperties(); 
    NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces(); 
    Console.WriteLine("Interface information for {0}.{1}  ", 
      computerProperties.HostName, computerProperties.DomainName); 
    if (nics == null || nics.Length < 1) 
    { 
     Console.WriteLine(" No network interfaces found."); 
     return; 
    } 

    Console.WriteLine(" Number of interfaces .................... : {0}", nics.Length); 
    foreach (NetworkInterface adapter in nics) 
    { 
     IPInterfaceProperties properties = adapter.GetIPProperties(); 
     Console.WriteLine(); 
     Console.WriteLine(adapter.Description); 
     Console.WriteLine(String.Empty.PadLeft(adapter.Description.Length,'=')); 
     Console.WriteLine(" Interface type .......................... : {0}", adapter.NetworkInterfaceType); 
     Console.WriteLine(" Physical Address ........................ : {0}", 
        adapter.GetPhysicalAddress().ToString()); 
     Console.WriteLine(" Operational status ...................... : {0}", 
      adapter.OperationalStatus); 

     Console.WriteLine(); 
    } 
} 
+0

確定,但基於這些特性,你怎麼能告訴我們,如果網絡接口是3G/EDGE/GPRS我試圖連接? 3G調制解調器連接到我的電腦,NetworkInterfaceType是「Ppp」,它不知道它是否是移動終端nection。 – 2010-09-13 10:00:29