【发布时间】:2009-07-04 19:01:45
【问题描述】:
我们的应用程序使用 RSS 从互联网下载数据,但在连接 3G 的机器上出现连接问题。我们想检测 3G、EDGE、GPRS 连接,以便我们可以更改应用程序行为、显示警告或连接状态。
如何做到这一点?
【问题讨论】:
标签: .net networking
我们的应用程序使用 RSS 从互联网下载数据,但在连接 3G 的机器上出现连接问题。我们想检测 3G、EDGE、GPRS 连接,以便我们可以更改应用程序行为、显示警告或连接状态。
如何做到这一点?
【问题讨论】:
标签: .net networking
System.Net.NetworkInformation 命名空间中的 NetworkInterface 类应该对您有用(更具体地说,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();
}
}
【讨论】: