断开连接而不断开连接?

时间:2015-12-21 15:02:58

标签: c#

对于我的一些项目,我必须禁用我的连接5秒,然后再次启用它。

我现在该怎么做(这不是最佳解决方案,但我使用的是Windows VPN):

  • 我已经设置了一个VPN,它不会让任何互联网低谷,这让我断断续续,但比Wi-Fi重新连接更快。

所以我基本上想知道一种断开连接的方法,比如连接到破损的VPN(没有Wi-Fi)。

在C#代码中。

这可能吗?

1 个答案:

答案 0 :(得分:0)

选择a look

使用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();
    }