gpt4 book ai didi

c# - 如何在 UWP 中检查有线互联网连接?

转载 作者:行者123 更新时间:2023-11-30 16:48:32 25 4
gpt4 key购买 nike

如何判断用户是否使用有线方式连接到互联网?

这是我目前的进度

var internetConnectionProfile = Windows.Networking.Connectivity.NetworkInformation.GetInternetConnectionProfile();

if (internetConnectionProfile.GetNetworkConnectivityLevel() == Windows.Networking.Connectivity.NetworkConnectivityLevel.InternetAccess)
{
// has internet connection
}
if (internetConnectionProfile.IsWwanConnectionProfile)
{
// its mobile
}
if (internetConnectionProfile.IsWlanConnectionProfile)
{
// its wireless
}

最佳答案

试试这个

bool IsWiredInternetAccess()
{
IReadOnlyList<ConnectionProfile> connections = NetworkInformation.GetConnectionProfiles();

foreach (var connection in connections)
{
if (connection == null) continue;

if (connection.GetNetworkConnectivityLevel() == NetworkConnectivityLevel.InternetAccess)
{
// check is connection wired
if ((connection.ConnectionProfile.IsWlanConnectionProfile)||(connection.IsWwanConnectionProfile))
{
// connection is Wlan or Wwan
return false;
}
else
{
return true;
}
}
}
}

关于c# - 如何在 UWP 中检查有线互联网连接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37985904/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com