检测在.NET中的3G互联网连接 [英] Detect a 3G internet connection in .NET

查看:132
本文介绍了检测在.NET中的3G互联网连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的应用程序下载使用RSS的互联网数据,但正在对3G网络连接设备的连接问题。我们要检测3G,EDGE,GPRS连接,这样我们就可以改变应用程序行为的连接,显示警告或状态。

Our application downloads data from the internet using RSS but is having connection problems on machines connecting with 3G. We'd like to detect 3G,EDGE,GPRS connections so that we can change the application behaviour, display warnings or status of connection.

这将如何做?

推荐答案

的的 的NetworkInterface System.Net.NetworkInformation 命名空间中的类应该是一些使用你(更具体地,<一href="http://msdn.microsoft.com/en-us/library/system.net.networkinformation.networkinterface.getallnetworkinterfaces.aspx"相对=nofollow> GetAllNetworkInterfaces 的方法。一个例子显示链接的MSDN页面,演示了如何获取类型,地址,运行状态上,等关于每一个网络接口的信息。

The NetworkInterface class in the System.Net.NetworkInformation namespace should be of some use to you (more specifically, the GetAllNetworkInterfaces method. An example is shown on the linked MSDN page that demonstrates how to get the type, address, operational status, and other information about every network interface.

减少MSDN例子的版本:

Reduced version of MSDN example:

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

这篇关于检测在.NET中的3G互联网连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆