如何检查连接的3G网络连接的状态? [英] How to check internet connection status over 3G connection?

查看:87
本文介绍了如何检查连接的3G网络连接的状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下方式:

public static bool IsNetworkConnected()
{
    ConnectionProfile InternetConnectionProfile = NetworkInformation.GetInternetConnectionProfile();
    IReadOnlyList<ConnectionProfile> connectionProfile = NetworkInformation.GetConnectionProfiles();
    if (InternetConnectionProfile == null)
        return false;
    else
        return true;
}



这当我在一个典型的方式连接到互联网的正常工作 - 通过LAN电缆或Wi-Fi。当我用我的3G USB调制解调器返回false( InternectConnectionProfile 为空)。这是为什么?我怎样才能解决这个问题?

It works fine when I'm connected to the internet in a typical way - via LAN cable or Wi-Fi. When I'm using my 3G USB modem it returns false (InternectConnectionProfile is null). Why is that? How can I fix it?

推荐答案

您可以考虑在互联网上ping一台服务器。这不是100%的回答你的问题,但可能有助于从不同的角度来看。

You may consider pinging a server on the internet. This is not the 100% answer to your question but may be helpful from a different point of view.

using System.Net;
using System.Net.NetworkInformation;

using (Ping Packet = new Ping()) 
{
    if (Packet.Send(IPAddress.Parse(IP), 1000, new byte[] { 0 }).Status ==   IPStatus.Success))
    {
       // ...
    }
}

这篇关于如何检查连接的3G网络连接的状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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