How to check internet connection status over 3G connection?(如何通过 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?
推荐答案
您可以考虑在 Internet 上 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 连接检查互联网连接状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何通过 3G 连接检查互联网连接状态?
基础教程推荐
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- WPF 模态进度窗口 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
