断开连接而不断开连接
本文关键字:断开 连接 | 更新日期: 2023-09-27 18:27:33
对于我的一些项目,我必须禁用我的连接大约5秒,然后再次启用它。
我现在该怎么做(这不是最好的解决方案,但我正在使用Windows VPN):
- 我设置了一个VPN,它不会让任何互联网通过,这让我有点断开连接,但比Wi-Fi重新连接更快
所以我基本上想知道一种断开连接的方法,比如连接到一个坏掉的VPN(没有Wi-Fi)。
在C#代码中。
这可能吗?
看看:
使用netsh命令,您可以启用和禁用"本地连接"
interfaceName is “Local Area Connection”.
static void Enable(string interfaceName)
{
System.Diagnostics.ProcessStartInfo psi =
new System.Diagnostics.ProcessStartInfo("netsh", "interface set interface '"" + interfaceName + "'" enable");
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo = psi;
p.Start();
}
static void Disable(string interfaceName)
{
System.Diagnostics.ProcessStartInfo psi =
new System.Diagnostics.ProcessStartInfo("netsh", "interface set interface '"" + interfaceName + "'" disable");
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo = psi;
p.Start();
}