diff --git a/Netch/Controllers/TUNTAPController.cs b/Netch/Controllers/TUNTAPController.cs index bb65ca7f..d3dd533b 100644 --- a/Netch/Controllers/TUNTAPController.cs +++ b/Netch/Controllers/TUNTAPController.cs @@ -5,6 +5,8 @@ using System.Net; using System.Text; using System.Threading; +using Netch.Utils; + namespace Netch.Controllers { public class TUNTAPController @@ -270,6 +272,7 @@ namespace Netch.Controllers Instance = new Process(); Instance.StartInfo.WorkingDirectory = string.Format("{0}\\bin", Directory.GetCurrentDirectory()); Instance.StartInfo.FileName = string.Format("{0}\\bin\\tun2socks.exe", Directory.GetCurrentDirectory()); + var adapterName = TUNTAP.GetName(Global.TUNTAP.ComponentID); string dns; if (Global.Settings.TUNTAP.UseCustomDNS) @@ -291,11 +294,11 @@ namespace Netch.Controllers if (server.Type == "Socks5") { - Instance.StartInfo.Arguments = string.Format("-proxyServer {0}:{1} -tunAddr {2} -tunMask {3} -tunGw {4} -tunDns {5} -tunName \"{6}\"", server.Hostname, server.Port, Global.Settings.TUNTAP.Address, Global.Settings.TUNTAP.Netmask, Global.Settings.TUNTAP.Gateway, dns, Global.TUNTAP.Adapter.Name); + Instance.StartInfo.Arguments = string.Format("-proxyServer {0}:{1} -tunAddr {2} -tunMask {3} -tunGw {4} -tunDns {5} -tunName \"{6}\"", server.Hostname, server.Port, Global.Settings.TUNTAP.Address, Global.Settings.TUNTAP.Netmask, Global.Settings.TUNTAP.Gateway, dns, adapterName); } else { - Instance.StartInfo.Arguments = string.Format("-proxyServer 127.0.0.1:{0} -tunAddr {1} -tunMask {2} -tunGw {3} -tunDns {4} -tunName \"{5}\"", Global.Settings.Socks5LocalPort, Global.Settings.TUNTAP.Address, Global.Settings.TUNTAP.Netmask, Global.Settings.TUNTAP.Gateway, dns, Global.TUNTAP.Adapter.Name); + Instance.StartInfo.Arguments = string.Format("-proxyServer 127.0.0.1:{0} -tunAddr {1} -tunMask {2} -tunGw {3} -tunDns {4} -tunName \"{5}\"", Global.Settings.Socks5LocalPort, Global.Settings.TUNTAP.Address, Global.Settings.TUNTAP.Netmask, Global.Settings.TUNTAP.Gateway, dns, adapterName); } Instance.StartInfo.CreateNoWindow = true; diff --git a/Netch/Utils/Configuration.cs b/Netch/Utils/Configuration.cs index 76e0bc46..d2671a53 100644 --- a/Netch/Utils/Configuration.cs +++ b/Netch/Utils/Configuration.cs @@ -165,18 +165,19 @@ namespace Netch.Utils // return false; } - var name = TUNTAP.GetName(Global.TUNTAP.ComponentID); foreach (var adapter in NetworkInterface.GetAllNetworkInterfaces()) { - if (adapter.Name == name) + if (adapter.Id == Global.TUNTAP.ComponentID) { Global.TUNTAP.Adapter = adapter; Global.TUNTAP.Index = adapter.GetIPProperties().GetIPv4Properties().Index; - break; + return true; } } - return true; + + Logging.Info("无法找到出口"); + return false; } } }