From 6f817ee2453bd3afe462d734dd99cb109a37ee55 Mon Sep 17 00:00:00 2001 From: henning Date: Thu, 27 Feb 2020 12:35:37 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=9B=B4=E5=A4=9Atun/tap?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E5=8F=8D=E9=A6=88=E4=BF=A1=E6=81=AF=E5=88=B0?= =?UTF-8?q?application.log?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Netch/Controllers/TUNTAPController.cs | 7 +++++-- Netch/Utils/Configuration.cs | 10 +++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/Netch/Controllers/TUNTAPController.cs b/Netch/Controllers/TUNTAPController.cs index d3dd533b..6fcb36a8 100644 --- a/Netch/Controllers/TUNTAPController.cs +++ b/Netch/Controllers/TUNTAPController.cs @@ -266,13 +266,16 @@ namespace Netch.Controllers { return false; } - + + Logging.Info("设置绕行规则"); SetupBypass(); + Logging.Info("设置绕行规则完毕"); 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); + Logging.Info($"tun2sock使用适配器:{adapterName}"); string dns; if (Global.Settings.TUNTAP.UseCustomDNS) @@ -299,7 +302,7 @@ namespace Netch.Controllers 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, adapterName); - } + } Instance.StartInfo.CreateNoWindow = true; Instance.StartInfo.RedirectStandardError = true; diff --git a/Netch/Utils/Configuration.cs b/Netch/Utils/Configuration.cs index d2671a53..67cf0b5e 100644 --- a/Netch/Utils/Configuration.cs +++ b/Netch/Utils/Configuration.cs @@ -105,6 +105,7 @@ namespace Netch.Utils return false; } + var AddressGot = false; foreach (var adapter in NetworkInterface.GetAllNetworkInterfaces()) { var adapterProperties = adapter.GetIPProperties(); @@ -113,7 +114,6 @@ namespace Netch.Utils // 通过索引查找对应适配器的 IPv4 地址 if (p.Index == Global.Adapter.Index) { - var AddressGot = false; var AdapterIPs = ""; foreach (var ip in adapterProperties.UnicastAddresses) @@ -142,6 +142,12 @@ namespace Netch.Utils } } + if (!AddressGot) + { + Logging.Info("无法找到ipv4地址"); + return false; + } + // 搜索 TUN/TAP 适配器的索引 Global.TUNTAP.ComponentID = TUNTAP.GetComponentID(); if (string.IsNullOrEmpty(Global.TUNTAP.ComponentID)) @@ -172,6 +178,8 @@ namespace Netch.Utils Global.TUNTAP.Adapter = adapter; Global.TUNTAP.Index = adapter.GetIPProperties().GetIPv4Properties().Index; + Logging.Info($"找到适配器:{adapter.Id}"); + return true; } } From 48ab9a8995fc563dfd13a34f6c81d3f7d040a04c Mon Sep 17 00:00:00 2001 From: henning Date: Thu, 27 Feb 2020 15:33:09 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=AF=BB=E6=89=BE?= =?UTF-8?q?=E9=80=82=E9=85=8D=E5=99=A8=E7=9A=84logging?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Netch/Utils/Configuration.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Netch/Utils/Configuration.cs b/Netch/Utils/Configuration.cs index 67cf0b5e..505de365 100644 --- a/Netch/Utils/Configuration.cs +++ b/Netch/Utils/Configuration.cs @@ -105,11 +105,13 @@ namespace Netch.Utils return false; } + Logging.Info($"搜索适配器index:{Global.Adapter.Index}"); var AddressGot = false; foreach (var adapter in NetworkInterface.GetAllNetworkInterfaces()) { var adapterProperties = adapter.GetIPProperties(); var p = adapterProperties.GetIPv4Properties(); + Logging.Info($"检测适配器:{adapter.Name} {adapter.Id} {adapter.Description}, index: {p.Index}"); // 通过索引查找对应适配器的 IPv4 地址 if (p.Index == Global.Adapter.Index) @@ -144,7 +146,7 @@ namespace Netch.Utils if (!AddressGot) { - Logging.Info("无法找到ipv4地址"); + Logging.Info("无法找到当前使用适配器"); return false; } From 2ae4f454ffdf1a0c57dc8345006bb9542b85c532 Mon Sep 17 00:00:00 2001 From: henning Date: Thu, 27 Feb 2020 15:45:39 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E5=BD=93logging?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=A4=B9=E5=AD=98=E5=9C=A8=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E5=90=AF=E5=8A=A8=E5=B4=A9=E6=BA=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Netch/Netch.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Netch/Netch.cs b/Netch/Netch.cs index 097f643f..afcc5c82 100644 --- a/Netch/Netch.cs +++ b/Netch/Netch.cs @@ -24,7 +24,17 @@ namespace Netch // 清理上一次的日志文件,防止淤积占用磁盘空间 if (Directory.Exists("logging")) { - Directory.Delete("logging", true); + DirectoryInfo directory = new DirectoryInfo("logging"); + + foreach (FileInfo file in directory.GetFiles()) + { + file.Delete(); + } + + foreach (DirectoryInfo dir in directory.GetDirectories()) + { + dir.Delete(true); + } } // 预创建目录