【问题标题】:Detect a 3G internet connection in .NET在 .NET 中检测 3G 互联网连接
【发布时间】:2009-07-04 19:01:45
【问题描述】:

我们的应用程序使用 RSS 从互联网下载数据,但在连接 3G 的机器上出现连接问题。我们想检测 3G、EDGE、GPRS 连接,以便我们可以更改应用程序行为、显示警告或连接状态。

如何做到这一点?

【问题讨论】:

    标签: .net networking


    【解决方案1】:

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

    【讨论】:

    • 好的,但是根据这些属性,如何判断网络接口是 3G/EDGE/GPRS 呢?我尝试将 3G 调制解调器连接到我的 PC,NetworkInterfaceType 为“Ppp”,无法判断它是否是移动连接。
    猜你喜欢
    • 2012-01-17
    • 1970-01-01
    • 2019-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-24
    • 1970-01-01
    相关资源
    最近更新 更多