Flutter判断设备是否连接了VPN
作者:
OwenWong | 来源:发表于
2023-03-20 10:25 被阅读0次
代码:
class CheckVpnConnectionStatus {
/// 如果设备具有 VPN 连接,返回 true
static Future<bool> isVpnActive() async {
bool isVpnActive;
List<NetworkInterface> interfaces = await NetworkInterface.list(includeLoopback: false, type: InternetAddressType.any);
interfaces.isNotEmpty ? isVpnActive = interfaces.any((interface) =>
interface.name.contains("tun") || interface.name.contains("ppp") || interface.name.contains("pptp")) : isVpnActive = false;
return isVpnActive;
}
}
使用:
if (await CheckVpnConnectionStatus.isVpnActive()) {
// existence vpn connect
}
本文标题:Flutter判断设备是否连接了VPN
本文链接:https://www.haomeiwen.com/subject/fauurdtx.html
网友评论