我正在试图弄清楚如何检查我的VPN连接是否处于活动状态。
使用此代码,我可以看到所有网络连接
Dim nics As NetworkInterface() = NetworkInterface.GetAllNetworkInterfaces
If nics.Length < 0 Or nics Is Nothing Then
MsgBox("No NICS")
Exit Sub
End If
ListBox1.Items.Clear()
For Each netadapter As NetworkInterface In nics
Dim intproperties As IPInterfaceProperties = netadapter.GetIPProperties()
ListBox1.Items.Add(netadapter.Name)
Next
当我的vpn连接处于活动状态时,我会在该列表中看到“VPN”
如何检查该列表中是否没有“VPN”,甚至没有ListBox?
答案 0 :(得分:0)
您可以对该任务使用LINQ查询:
Dim isVpnExist As Boolean = nics.AsEnumerable().Any(Function(x) x.Name = "VPN")
If isVpnExist = True Then
' vpn exist do something
Else
' vpn is not exist do something
End If