From aad2751c44eb2cc52ea410d39f13c95cefa6ed7e Mon Sep 17 00:00:00 2001 From: Daniel Lenski Date: Wed, 31 Mar 2021 14:56:38 -0700 Subject: [PATCH] vpnc-script-win: delete DNS and WINS servers before adding them MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit If not, "leftover" servers will persist from previous use of the adapter. This will result in errors: "The object is already in the list." And also could be a source of buggy behavior, even security issues, if the "same" TAP/TUN adapter was used to access a different VPN. 🙊 Signed-off-by: Daniel Lenski --- vpnc-script-win.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/vpnc-script-win.js b/vpnc-script-win.js index d69f5ed..3b698f6 100644 --- a/vpnc-script-win.js +++ b/vpnc-script-win.js @@ -105,22 +105,23 @@ case "connect": run("route add " + env("VPNGATEWAY") + " mask 255.255.255.255 " + gw); + run("netsh interface ipv4 del wins " + env("TUNIDX") + " all"); if (env("INTERNAL_IP4_NBNS")) { var wins = env("INTERNAL_IP4_NBNS").split(/ /); for (var i = 0; i < wins.length; i++) { - run("netsh interface ip add wins " + - env("TUNIDX") + " " + wins[i] - + " index=" + (i+1)); + run("netsh interface ipv4 add wins " + + env("TUNIDX") + " " + wins[i]); } } + run("netsh interface ipv4 del dns " + env("TUNIDX") + " all"); + run("netsh interface ipv6 del dns " + env("TUNIDX") + " all"); if (env("INTERNAL_IP4_DNS")) { var dns = env("INTERNAL_IP4_DNS").split(/ /); for (var i = 0; i < dns.length; i++) { var protocol = dns[i].indexOf(":") !== -1 ? "ipv6" : "ipv4"; run("netsh interface " + protocol + " add dns " + - env("TUNIDX") + " " + dns[i] - + " index=" + (i+1)); + env("TUNIDX") + " " + dns[i]); } } echo("done."); -- 2.50.1