我正在使用NetworkInterface.GetAllNetworkInterfaces()获取PC上的所有接口(interface)。然而,这似乎只返回“事件”接口(interface)。如何在 .NET 中找到“不活动”的网络接口(interface),例如未连接的 VPN、禁用的 NIC 等。
我想在“控制面板”->“网络连接”中按名称找到它们。因此,举例来说,如果我有一个名为“My Work”的 VPN,我希望能够使用名称“My Work”找到它。
使用 Win32_NetworkAdapterConfiguration 似乎不是一个选项,因为它不会返回“网络连接”中显示的名称(据我所知)。
非常感谢,
RB。
最佳答案
好吧,这是一个我用来检测命名 VPN 的黑客解决方案。如果由于任何原因(包括网络连接断开、VPN 不存在等)无法连接到 VPN,则会抛出错误。
要测试的具体错误代码包括:
Remote Access error 800 - Unable to establish the VPN connection.
The VPN server may be unreachable, or security parameters may not be configured properly for this connection.Remote Access error 623 - The system could not find the phone book entry for this connection.
它并没有真正回答我提出的问题(尽管它足以解决现实生活中的问题)。
Dim p As New Process
p.StartInfo.UseShellExecute = False
p.StartInfo.RedirectStandardOutput = True
p.StartInfo.RedirectStandardError = True
p.StartInfo.FileName = "rasdial.exe"
p.StartInfo.Arguments = """Company HQ"""
p.Start()
If Not p.WaitForExit(My.Settings.VpnTimeout) Then
Throw New Exception( _
String.Format("Connecting to ""{0}"" VPN failed after {1}ms", sVpn, My.Settings.VpnTimeout))
End If
If p.ExitCode <> 0 Then
Throw New Exception( _
String.Format("Failed connecting to ""{0}"" with exit code {1}. Errors {2}", sVpn, p.ExitCode, p.StandardOutput.ReadToEnd.Replace(vbCrLf, "")))
End If
关于.net - 在 VB .NET 中查找并启动 VPN 连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/349729/