mirror of
https://github.com/netchx/netch.git
synced 2026-05-11 23:45:06 +08:00
Compare commits
18 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bd05f875f2 | ||
|
|
ea3fb188e4 | ||
|
|
ee3ac561b5 | ||
|
|
4fb090d7a4 | ||
|
|
9302900b5d | ||
|
|
6dd50f1510 | ||
|
|
91f73b936d | ||
|
|
9ddcc3ae3c | ||
|
|
9d637a3c67 | ||
|
|
8ff8582dd7 | ||
|
|
b76a22da33 | ||
|
|
ee61c5dbd3 | ||
|
|
658ed3245f | ||
|
|
d443c6d311 | ||
|
|
caa6b8fa94 | ||
|
|
26af839d01 | ||
|
|
08db39f72b | ||
|
|
5e1f25a27e |
112
Netch/Controllers/DNSController.cs
Normal file
112
Netch/Controllers/DNSController.cs
Normal file
@@ -0,0 +1,112 @@
|
|||||||
|
using Netch.Forms;
|
||||||
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.IO;
|
||||||
|
using System.Net;
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
|
namespace Netch.Controllers
|
||||||
|
{
|
||||||
|
public class DNSController
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 进程实例
|
||||||
|
/// </summary>
|
||||||
|
public Process Instance;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 启动NatTypeTester
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public bool Start()
|
||||||
|
{
|
||||||
|
MainForm.Instance.StatusText($"{Utils.i18N.Translate("Starting dns2tcp Service")}");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (!File.Exists("bin\\dns2tcp.exe"))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Instance = MainController.GetProcess();
|
||||||
|
Instance.StartInfo.FileName = "bin\\dns2tcp.exe";
|
||||||
|
|
||||||
|
Instance.StartInfo.Arguments = " -L 127.0.0.1:53 -R 1.1.1.1:53";
|
||||||
|
|
||||||
|
Instance.OutputDataReceived += OnOutputDataReceived;
|
||||||
|
Instance.ErrorDataReceived += OnOutputDataReceived;
|
||||||
|
|
||||||
|
Instance.Start();
|
||||||
|
Instance.BeginOutputReadLine();
|
||||||
|
Instance.BeginErrorReadLine();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
Utils.Logging.Info("dns2tcp 进程出错");
|
||||||
|
Stop();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 停止
|
||||||
|
/// </summary>
|
||||||
|
public void Stop()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (Instance != null && !Instance.HasExited)
|
||||||
|
{
|
||||||
|
Instance.Kill();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Utils.Logging.Info(e.ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnOutputDataReceived(object sender, DataReceivedEventArgs e)
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrWhiteSpace(e.Data))
|
||||||
|
{
|
||||||
|
if (File.Exists("logging\\dns2tcp.log"))
|
||||||
|
{
|
||||||
|
File.Delete("logging\\dns2tcp.log");
|
||||||
|
}
|
||||||
|
File.AppendAllText("logging\\dns2tcp.log", $"{e.Data}\r\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* public static DNS.Server.DnsServer Server = new DNS.Server.DnsServer(new Resolver());
|
||||||
|
|
||||||
|
public bool Start()
|
||||||
|
{
|
||||||
|
MainForm.Instance.StatusText($"{Utils.i18N.Translate("Status")}{Utils.i18N.Translate(": ")}{Utils.i18N.Translate("Starting LocalDns service")}");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_ = Server.Listen(new IPEndPoint(IPAddress.IPv6Any, 53));
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Utils.Logging.Info(e.ToString());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Stop()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Server.Dispose();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Utils.Logging.Info(e.ToString());
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Netch.Controllers
|
namespace Netch.Controllers
|
||||||
{
|
{
|
||||||
@@ -51,6 +52,11 @@ namespace Netch.Controllers
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public TUNTAPController pTUNTAPController;
|
public TUNTAPController pTUNTAPController;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// NTT 控制器
|
||||||
|
/// </summary>
|
||||||
|
public NTTController pNTTController;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 启动
|
/// 启动
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -106,8 +112,18 @@ namespace Netch.Controllers
|
|||||||
{
|
{
|
||||||
pNFController = new NFController();
|
pNFController = new NFController();
|
||||||
}
|
}
|
||||||
|
if (pNTTController == null)
|
||||||
|
{
|
||||||
|
pNTTController = new NTTController();
|
||||||
|
}
|
||||||
// 进程代理模式,启动 NF 控制器
|
// 进程代理模式,启动 NF 控制器
|
||||||
result = pNFController.Start(server, mode);
|
result = pNFController.Start(server, mode);
|
||||||
|
|
||||||
|
Task.Run(() =>
|
||||||
|
{
|
||||||
|
pNTTController.Start();
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (mode.Type == 1)
|
else if (mode.Type == 1)
|
||||||
{
|
{
|
||||||
@@ -115,8 +131,17 @@ namespace Netch.Controllers
|
|||||||
{
|
{
|
||||||
pTUNTAPController = new TUNTAPController();
|
pTUNTAPController = new TUNTAPController();
|
||||||
}
|
}
|
||||||
|
if (pNTTController == null)
|
||||||
|
{
|
||||||
|
pNTTController = new NTTController();
|
||||||
|
}
|
||||||
// TUN/TAP 黑名单代理模式,启动 TUN/TAP 控制器
|
// TUN/TAP 黑名单代理模式,启动 TUN/TAP 控制器
|
||||||
result = pTUNTAPController.Start(server, mode);
|
result = pTUNTAPController.Start(server, mode);
|
||||||
|
|
||||||
|
Task.Run(() =>
|
||||||
|
{
|
||||||
|
pNTTController.Start();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
else if (mode.Type == 2)
|
else if (mode.Type == 2)
|
||||||
{
|
{
|
||||||
@@ -124,8 +149,17 @@ namespace Netch.Controllers
|
|||||||
{
|
{
|
||||||
pTUNTAPController = new TUNTAPController();
|
pTUNTAPController = new TUNTAPController();
|
||||||
}
|
}
|
||||||
|
if (pNTTController == null)
|
||||||
|
{
|
||||||
|
pNTTController = new NTTController();
|
||||||
|
}
|
||||||
// TUN/TAP 白名单代理模式,启动 TUN/TAP 控制器
|
// TUN/TAP 白名单代理模式,启动 TUN/TAP 控制器
|
||||||
result = pTUNTAPController.Start(server, mode);
|
result = pTUNTAPController.Start(server, mode);
|
||||||
|
|
||||||
|
Task.Run(() =>
|
||||||
|
{
|
||||||
|
pNTTController.Start();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
else if (mode.Type == 3 || mode.Type == 5)
|
else if (mode.Type == 3 || mode.Type == 5)
|
||||||
{
|
{
|
||||||
@@ -171,7 +205,7 @@ namespace Netch.Controllers
|
|||||||
{
|
{
|
||||||
pVMessController.Stop();
|
pVMessController.Stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pNFController != null)
|
if (pNFController != null)
|
||||||
{
|
{
|
||||||
pNFController.Stop();
|
pNFController.Stop();
|
||||||
@@ -184,10 +218,15 @@ namespace Netch.Controllers
|
|||||||
{
|
{
|
||||||
pHTTPController.Stop();
|
pHTTPController.Stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (pNTTController != null)
|
||||||
|
{
|
||||||
|
pNTTController.Stop();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void KillProcess(string name) {
|
public void KillProcess(string name)
|
||||||
|
{
|
||||||
var processes = Process.GetProcessesByName(name);
|
var processes = Process.GetProcessesByName(name);
|
||||||
foreach (var p in processes)
|
foreach (var p in processes)
|
||||||
{
|
{
|
||||||
@@ -198,7 +237,7 @@ namespace Netch.Controllers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool IsChildProcess(Process process,string name)
|
private static bool IsChildProcess(Process process, string name)
|
||||||
{
|
{
|
||||||
bool result;
|
bool result;
|
||||||
try
|
try
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using Netch.Forms;
|
||||||
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.ServiceProcess;
|
using System.ServiceProcess;
|
||||||
@@ -39,6 +40,7 @@ namespace Netch.Controllers
|
|||||||
/// <returns>是否成功</returns>
|
/// <returns>是否成功</returns>
|
||||||
public bool Start(Models.Server server, Models.Mode mode)
|
public bool Start(Models.Server server, Models.Mode mode)
|
||||||
{
|
{
|
||||||
|
MainForm.Instance.StatusText($"{Utils.i18N.Translate("Status")}{Utils.i18N.Translate(": ")}{Utils.i18N.Translate("Starting Redirector")}");
|
||||||
if (!File.Exists("bin\\Redirector.exe"))
|
if (!File.Exists("bin\\Redirector.exe"))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
@@ -98,6 +100,7 @@ namespace Netch.Controllers
|
|||||||
var service = new ServiceController("netfilter2");
|
var service = new ServiceController("netfilter2");
|
||||||
if (service.Status == ServiceControllerStatus.Stopped)
|
if (service.Status == ServiceControllerStatus.Stopped)
|
||||||
{
|
{
|
||||||
|
MainForm.Instance.StatusText($"{Utils.i18N.Translate("Status")}{Utils.i18N.Translate(": ")}{Utils.i18N.Translate("Starting netfilter2 Service")}");
|
||||||
service.Start();
|
service.Start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -113,7 +116,8 @@ namespace Netch.Controllers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var processes = "";
|
var processes = "NTT.exe,";
|
||||||
|
|
||||||
foreach (var proc in mode.Rule)
|
foreach (var proc in mode.Rule)
|
||||||
{
|
{
|
||||||
processes += proc;
|
processes += proc;
|
||||||
@@ -147,7 +151,7 @@ namespace Netch.Controllers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Instance.StartInfo.Arguments = fallback + $" -t {Global.Settings.RedirectorTCPPort}";
|
Instance.StartInfo.Arguments = fallback;
|
||||||
Instance.OutputDataReceived += OnOutputDataReceived;
|
Instance.OutputDataReceived += OnOutputDataReceived;
|
||||||
Instance.ErrorDataReceived += OnOutputDataReceived;
|
Instance.ErrorDataReceived += OnOutputDataReceived;
|
||||||
State = Models.State.Starting;
|
State = Models.State.Starting;
|
||||||
@@ -155,7 +159,6 @@ namespace Netch.Controllers
|
|||||||
Instance.BeginOutputReadLine();
|
Instance.BeginOutputReadLine();
|
||||||
Instance.BeginErrorReadLine();
|
Instance.BeginErrorReadLine();
|
||||||
|
|
||||||
var IsFallback = false;
|
|
||||||
for (var i = 0; i < 1000; i++)
|
for (var i = 0; i < 1000; i++)
|
||||||
{
|
{
|
||||||
Thread.Sleep(10);
|
Thread.Sleep(10);
|
||||||
@@ -164,33 +167,6 @@ namespace Netch.Controllers
|
|||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (State == Models.State.Stopped)
|
|
||||||
{
|
|
||||||
if (!IsFallback)
|
|
||||||
{
|
|
||||||
IsFallback = true;
|
|
||||||
Stop();
|
|
||||||
Utils.Logging.Info($"尝试去除 \"-t {Global.Settings.RedirectorTCPPort}\" 参数后启动 \"bin\\Redirector.exe\"");
|
|
||||||
Instance.StartInfo.Arguments = fallback;
|
|
||||||
Utils.Logging.Info($"当前 \"bin\\Redirector.exe\" 启动参数为 \"{Instance.StartInfo.Arguments}\"");
|
|
||||||
Global.Settings.RedirectorTCPPort = 2800;
|
|
||||||
Instance.CancelOutputRead();
|
|
||||||
Instance.CancelErrorRead();
|
|
||||||
Instance.OutputDataReceived += OnOutputDataReceived;
|
|
||||||
Instance.ErrorDataReceived += OnOutputDataReceived;
|
|
||||||
State = Models.State.Starting;
|
|
||||||
Instance.Start();
|
|
||||||
Instance.BeginOutputReadLine();
|
|
||||||
Instance.BeginErrorReadLine();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Utils.Logging.Info("NF 进程启动失败");
|
|
||||||
Stop();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Utils.Logging.Info("NF 进程启动超时");
|
Utils.Logging.Info("NF 进程启动超时");
|
||||||
@@ -229,7 +205,7 @@ namespace Netch.Controllers
|
|||||||
{
|
{
|
||||||
State = Models.State.Stopped;
|
State = Models.State.Stopped;
|
||||||
}
|
}
|
||||||
else if (e.Data.Contains("Started"))
|
else if (e.Data.Contains("Redirect to"))
|
||||||
{
|
{
|
||||||
State = Models.State.Started;
|
State = Models.State.Started;
|
||||||
}
|
}
|
||||||
|
|||||||
95
Netch/Controllers/NTTController.cs
Normal file
95
Netch/Controllers/NTTController.cs
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
using Netch.Forms;
|
||||||
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.IO;
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
|
namespace Netch.Controllers
|
||||||
|
{
|
||||||
|
public class NTTController
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 进程实例
|
||||||
|
/// </summary>
|
||||||
|
public Process Instance;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 当前状态
|
||||||
|
/// </summary>
|
||||||
|
public Models.State State = Models.State.Waiting;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 启动NatTypeTester
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public (bool, string, string, string) Start()
|
||||||
|
{
|
||||||
|
MainForm.Instance.NatTypeStatusText($"{Utils.i18N.Translate("Starting NatTester")}");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (!File.Exists("bin\\NTT.exe"))
|
||||||
|
{
|
||||||
|
return (false, null, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
Instance = MainController.GetProcess();
|
||||||
|
Instance.StartInfo.FileName = "bin\\NTT.exe";
|
||||||
|
|
||||||
|
Instance.StartInfo.Arguments = $" {Global.Settings.STUN_Server} {Global.Settings.STUN_Server_Port}";
|
||||||
|
|
||||||
|
Instance.OutputDataReceived += OnOutputDataReceived;
|
||||||
|
Instance.ErrorDataReceived += OnOutputDataReceived;
|
||||||
|
|
||||||
|
State = Models.State.Starting;
|
||||||
|
Instance.Start();
|
||||||
|
Instance.BeginOutputReadLine();
|
||||||
|
Instance.BeginErrorReadLine();
|
||||||
|
Instance.WaitForExit();
|
||||||
|
|
||||||
|
string[] result = File.ReadAllText("logging\\NTT.log").ToString().Split('#');
|
||||||
|
var natType = result[0];
|
||||||
|
var localEnd = result[1];
|
||||||
|
var publicEnd = result[2];
|
||||||
|
MainForm.Instance.NatTypeStatusText(natType);
|
||||||
|
|
||||||
|
return (true, natType, localEnd, publicEnd);
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
Utils.Logging.Info("NTT 进程出错");
|
||||||
|
Stop();
|
||||||
|
return (false, null, null, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 停止
|
||||||
|
/// </summary>
|
||||||
|
public void Stop()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (Instance != null && !Instance.HasExited)
|
||||||
|
{
|
||||||
|
Instance.Kill();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Utils.Logging.Info(e.ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnOutputDataReceived(object sender, DataReceivedEventArgs e)
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrWhiteSpace(e.Data))
|
||||||
|
{
|
||||||
|
if (File.Exists("logging\\NTT.log"))
|
||||||
|
{
|
||||||
|
File.Delete("logging\\NTT.log");
|
||||||
|
}
|
||||||
|
File.AppendAllText("logging\\NTT.log", $"{e.Data}\r\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using Netch.Forms;
|
||||||
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
@@ -25,6 +26,7 @@ namespace Netch.Controllers
|
|||||||
/// <returns>是否启动成功</returns>
|
/// <returns>是否启动成功</returns>
|
||||||
public bool Start(Models.Server server, Models.Mode mode)
|
public bool Start(Models.Server server, Models.Mode mode)
|
||||||
{
|
{
|
||||||
|
MainForm.Instance.StatusText($"{Utils.i18N.Translate("Status")}{Utils.i18N.Translate(": ")}{Utils.i18N.Translate("Starting Shadowsocks")}");
|
||||||
if (!File.Exists("bin\\Shadowsocks.exe"))
|
if (!File.Exists("bin\\Shadowsocks.exe"))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using Netch.Forms;
|
||||||
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
@@ -25,6 +26,7 @@ namespace Netch.Controllers
|
|||||||
/// <returns>是否启动成功</returns>
|
/// <returns>是否启动成功</returns>
|
||||||
public bool Start(Models.Server server, Models.Mode mode)
|
public bool Start(Models.Server server, Models.Mode mode)
|
||||||
{
|
{
|
||||||
|
MainForm.Instance.StatusText($"{Utils.i18N.Translate("Status")}{Utils.i18N.Translate(": ")}{Utils.i18N.Translate("Starting ShadowsocksR")}");
|
||||||
if (!File.Exists("bin\\ShadowsocksR.exe"))
|
if (!File.Exists("bin\\ShadowsocksR.exe"))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ using System.IO;
|
|||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
using Netch.Forms;
|
||||||
using Netch.Utils;
|
using Netch.Utils;
|
||||||
|
|
||||||
namespace Netch.Controllers
|
namespace Netch.Controllers
|
||||||
@@ -32,6 +32,11 @@ namespace Netch.Controllers
|
|||||||
public Models.Server SavedServer = new Models.Server();
|
public Models.Server SavedServer = new Models.Server();
|
||||||
public Models.Mode SavedMode = new Models.Mode();
|
public Models.Mode SavedMode = new Models.Mode();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 本地 DNS 服务控制器
|
||||||
|
/// </summary>
|
||||||
|
public DNSController pDNSController = new DNSController();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 配置 TUNTAP 适配器
|
/// 配置 TUNTAP 适配器
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -58,6 +63,7 @@ namespace Netch.Controllers
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public bool SetupBypass()
|
public bool SetupBypass()
|
||||||
{
|
{
|
||||||
|
MainForm.Instance.StatusText($"{Utils.i18N.Translate("Status")}{Utils.i18N.Translate(": ")}{Utils.i18N.Translate("SetupBypass")}");
|
||||||
// 让服务器 IP 走直连
|
// 让服务器 IP 走直连
|
||||||
foreach (var address in ServerAddresses)
|
foreach (var address in ServerAddresses)
|
||||||
{
|
{
|
||||||
@@ -237,6 +243,7 @@ namespace Netch.Controllers
|
|||||||
/// <returns>是否成功</returns>
|
/// <returns>是否成功</returns>
|
||||||
public bool Start(Models.Server server, Models.Mode mode)
|
public bool Start(Models.Server server, Models.Mode mode)
|
||||||
{
|
{
|
||||||
|
MainForm.Instance.StatusText($"{Utils.i18N.Translate("Status")}{Utils.i18N.Translate(": ")}{Utils.i18N.Translate("Starting Tap")}");
|
||||||
foreach (var proc in Process.GetProcessesByName("tun2socks"))
|
foreach (var proc in Process.GetProcessesByName("tun2socks"))
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@@ -292,7 +299,9 @@ namespace Netch.Controllers
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
dns = "1.1.1.1,1.0.0.1";
|
pDNSController.Start();
|
||||||
|
dns = "127.0.0.1";
|
||||||
|
//dns = "1.1.1.1,1.0.0.1";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (server.Type == "Socks5")
|
if (server.Type == "Socks5")
|
||||||
@@ -353,6 +362,7 @@ namespace Netch.Controllers
|
|||||||
//pDNSController.Stop();
|
//pDNSController.Stop();
|
||||||
//修复点击停止按钮后再启动,DNS服务没监听的BUG
|
//修复点击停止按钮后再启动,DNS服务没监听的BUG
|
||||||
ClearBypass();
|
ClearBypass();
|
||||||
|
pDNSController.Stop();
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ namespace Netch.Controllers
|
|||||||
|
|
||||||
public const string Name = @"Netch";
|
public const string Name = @"Netch";
|
||||||
public const string Copyright = @"Copyright © 2019 - 2020";
|
public const string Copyright = @"Copyright © 2019 - 2020";
|
||||||
public const string Version = @"1.3.8";
|
public const string Version = @"1.4.0";
|
||||||
|
|
||||||
public async void Check(bool notifyNoFound, bool isPreRelease)
|
public async void Check(bool notifyNoFound, bool isPreRelease)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using Netch.Forms;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
@@ -26,6 +27,7 @@ namespace Netch.Controllers
|
|||||||
/// <returns>是否启动成功</returns>
|
/// <returns>是否启动成功</returns>
|
||||||
public bool Start(Models.Server server, Models.Mode mode)
|
public bool Start(Models.Server server, Models.Mode mode)
|
||||||
{
|
{
|
||||||
|
MainForm.Instance.StatusText($"{Utils.i18N.Translate("Status")}{Utils.i18N.Translate(": ")}{Utils.i18N.Translate("Starting V2ray")}");
|
||||||
if (!File.Exists("bin\\v2ray.exe") || !File.Exists("bin\\v2ctl.exe"))
|
if (!File.Exists("bin\\v2ray.exe") || !File.Exists("bin\\v2ctl.exe"))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
11
Netch/Forms/MainForm.Designer.cs
generated
11
Netch/Forms/MainForm.Designer.cs
generated
@@ -78,6 +78,7 @@ namespace Netch.Forms
|
|||||||
this.SettingsButton = new System.Windows.Forms.Button();
|
this.SettingsButton = new System.Windows.Forms.Button();
|
||||||
this.ProfileGroupBox = new System.Windows.Forms.GroupBox();
|
this.ProfileGroupBox = new System.Windows.Forms.GroupBox();
|
||||||
this.ProfileTable = new System.Windows.Forms.TableLayoutPanel();
|
this.ProfileTable = new System.Windows.Forms.TableLayoutPanel();
|
||||||
|
this.NatTypeStatusLabel = new System.Windows.Forms.ToolStripStatusLabel();
|
||||||
this.MenuStrip.SuspendLayout();
|
this.MenuStrip.SuspendLayout();
|
||||||
this.ConfigurationGroupBox.SuspendLayout();
|
this.ConfigurationGroupBox.SuspendLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.CopyLinkPictureBox)).BeginInit();
|
((System.ComponentModel.ISupportInitialize)(this.CopyLinkPictureBox)).BeginInit();
|
||||||
@@ -421,7 +422,8 @@ namespace Netch.Forms
|
|||||||
this.StatusLabel,
|
this.StatusLabel,
|
||||||
this.UsedBandwidthLabel,
|
this.UsedBandwidthLabel,
|
||||||
this.DownloadSpeedLabel,
|
this.DownloadSpeedLabel,
|
||||||
this.UploadSpeedLabel});
|
this.UploadSpeedLabel,
|
||||||
|
this.NatTypeStatusLabel});
|
||||||
this.StatusStrip.Location = new System.Drawing.Point(0, 254);
|
this.StatusStrip.Location = new System.Drawing.Point(0, 254);
|
||||||
this.StatusStrip.Name = "StatusStrip";
|
this.StatusStrip.Name = "StatusStrip";
|
||||||
this.StatusStrip.Size = new System.Drawing.Size(629, 22);
|
this.StatusStrip.Size = new System.Drawing.Size(629, 22);
|
||||||
@@ -534,6 +536,12 @@ namespace Netch.Forms
|
|||||||
this.ProfileTable.Size = new System.Drawing.Size(599, 43);
|
this.ProfileTable.Size = new System.Drawing.Size(599, 43);
|
||||||
this.ProfileTable.TabIndex = 0;
|
this.ProfileTable.TabIndex = 0;
|
||||||
//
|
//
|
||||||
|
// NatTypeStatusLabel
|
||||||
|
//
|
||||||
|
this.NatTypeStatusLabel.Name = "NatTypeStatusLabel";
|
||||||
|
this.NatTypeStatusLabel.Size = new System.Drawing.Size(109, 17);
|
||||||
|
this.NatTypeStatusLabel.Text = "";
|
||||||
|
//
|
||||||
// MainForm
|
// MainForm
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
|
||||||
@@ -623,5 +631,6 @@ namespace Netch.Forms
|
|||||||
private System.Windows.Forms.PictureBox EditModePictureBox;
|
private System.Windows.Forms.PictureBox EditModePictureBox;
|
||||||
private System.Windows.Forms.PictureBox DeleteModePictureBox;
|
private System.Windows.Forms.PictureBox DeleteModePictureBox;
|
||||||
private System.Windows.Forms.PictureBox CopyLinkPictureBox;
|
private System.Windows.Forms.PictureBox CopyLinkPictureBox;
|
||||||
|
private System.Windows.Forms.ToolStripStatusLabel NatTypeStatusLabel;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -41,6 +41,11 @@ namespace Netch.Forms
|
|||||||
|
|
||||||
public List<Button> ProfileButtons = new List<Button>();
|
public List<Button> ProfileButtons = new List<Button>();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 主窗体的静态实例
|
||||||
|
/// </summary>
|
||||||
|
public static MainForm Instance = null;
|
||||||
|
|
||||||
public MainForm()
|
public MainForm()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
@@ -48,6 +53,7 @@ namespace Netch.Forms
|
|||||||
|
|
||||||
CheckForIllegalCrossThreadCalls = false;
|
CheckForIllegalCrossThreadCalls = false;
|
||||||
// MenuStrip.Renderer = new Override.ToolStripProfessionalRender();
|
// MenuStrip.Renderer = new Override.ToolStripProfessionalRender();
|
||||||
|
Instance = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CheckUpdate()
|
private void CheckUpdate()
|
||||||
@@ -232,60 +238,66 @@ namespace Netch.Forms
|
|||||||
|
|
||||||
private void ComboBox_DrawItem(object sender, DrawItemEventArgs e)
|
private void ComboBox_DrawItem(object sender, DrawItemEventArgs e)
|
||||||
{
|
{
|
||||||
var cbx = sender as ComboBox;
|
try
|
||||||
|
|
||||||
// 绘制背景颜色
|
|
||||||
e.Graphics.FillRectangle(new SolidBrush(Color.White), e.Bounds);
|
|
||||||
|
|
||||||
if (e.Index >= 0)
|
|
||||||
{
|
{
|
||||||
// 绘制 备注/名称 字符串
|
|
||||||
e.Graphics.DrawString(cbx.Items[e.Index].ToString(), cbx.Font, new SolidBrush(Color.Black), e.Bounds);
|
|
||||||
|
|
||||||
if (cbx.Items[e.Index] is Models.Server)
|
var cbx = sender as ComboBox;
|
||||||
|
|
||||||
|
// 绘制背景颜色
|
||||||
|
e.Graphics.FillRectangle(new SolidBrush(Color.White), e.Bounds);
|
||||||
|
|
||||||
|
if (e.Index >= 0)
|
||||||
{
|
{
|
||||||
var item = cbx.Items[e.Index] as Models.Server;
|
// 绘制 备注/名称 字符串
|
||||||
|
e.Graphics.DrawString(cbx.Items[e.Index].ToString(), cbx.Font, new SolidBrush(Color.Black), e.Bounds);
|
||||||
|
|
||||||
// 计算延迟底色
|
if (cbx.Items[e.Index] is Models.Server)
|
||||||
SolidBrush brush;
|
|
||||||
if (item.Delay > 200)
|
|
||||||
{
|
{
|
||||||
// 红色
|
var item = cbx.Items[e.Index] as Models.Server;
|
||||||
brush = new SolidBrush(Color.Red);
|
|
||||||
|
// 计算延迟底色
|
||||||
|
SolidBrush brush;
|
||||||
|
if (item.Delay > 200)
|
||||||
|
{
|
||||||
|
// 红色
|
||||||
|
brush = new SolidBrush(Color.Red);
|
||||||
|
}
|
||||||
|
else if (item.Delay > 80)
|
||||||
|
{
|
||||||
|
// 黄色
|
||||||
|
brush = new SolidBrush(Color.Yellow);
|
||||||
|
}
|
||||||
|
else if (item.Delay >= 0)
|
||||||
|
{
|
||||||
|
// 绿色
|
||||||
|
brush = new SolidBrush(Color.FromArgb(50, 255, 56));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// 灰色
|
||||||
|
brush = new SolidBrush(Color.Gray);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 绘制延迟底色
|
||||||
|
e.Graphics.FillRectangle(brush, ServerComboBox.Size.Width - 60, e.Bounds.Y, 60, e.Bounds.Height);
|
||||||
|
|
||||||
|
// 绘制延迟字符串
|
||||||
|
e.Graphics.DrawString(item.Delay.ToString(), cbx.Font, new SolidBrush(Color.Black), ServerComboBox.Size.Width - 58, e.Bounds.Y);
|
||||||
}
|
}
|
||||||
else if (item.Delay > 80)
|
else if (cbx.Items[e.Index] is Models.Mode)
|
||||||
{
|
{
|
||||||
// 黄色
|
var item = cbx.Items[e.Index] as Models.Mode;
|
||||||
brush = new SolidBrush(Color.Yellow);
|
|
||||||
|
// 绘制延迟底色
|
||||||
|
e.Graphics.FillRectangle(new SolidBrush(Color.Gray), ServerComboBox.Size.Width - 60, e.Bounds.Y, 60, e.Bounds.Height);
|
||||||
|
|
||||||
|
// 绘制延迟字符串
|
||||||
|
e.Graphics.DrawString(item.Rule.Count.ToString(), cbx.Font, new SolidBrush(Color.Black), ServerComboBox.Size.Width - 58, e.Bounds.Y);
|
||||||
}
|
}
|
||||||
else if (item.Delay >= 0)
|
|
||||||
{
|
|
||||||
// 绿色
|
|
||||||
brush = new SolidBrush(Color.FromArgb(50, 255, 56));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// 灰色
|
|
||||||
brush = new SolidBrush(Color.Gray);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 绘制延迟底色
|
|
||||||
e.Graphics.FillRectangle(brush, ServerComboBox.Size.Width - 60, e.Bounds.Y, 60, e.Bounds.Height);
|
|
||||||
|
|
||||||
// 绘制延迟字符串
|
|
||||||
e.Graphics.DrawString(item.Delay.ToString(), cbx.Font, new SolidBrush(Color.Black), ServerComboBox.Size.Width - 58, e.Bounds.Y);
|
|
||||||
}
|
|
||||||
else if (cbx.Items[e.Index] is Models.Mode)
|
|
||||||
{
|
|
||||||
var item = cbx.Items[e.Index] as Models.Mode;
|
|
||||||
|
|
||||||
// 绘制延迟底色
|
|
||||||
e.Graphics.FillRectangle(new SolidBrush(Color.Gray), ServerComboBox.Size.Width - 60, e.Bounds.Y, 60, e.Bounds.Height);
|
|
||||||
|
|
||||||
// 绘制延迟字符串
|
|
||||||
e.Graphics.DrawString(item.Rule.Count.ToString(), cbx.Font, new SolidBrush(Color.Black), ServerComboBox.Size.Width - 58, e.Bounds.Y);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{ }
|
||||||
}
|
}
|
||||||
|
|
||||||
private void MainForm_Load(object sender, EventArgs e)
|
private void MainForm_Load(object sender, EventArgs e)
|
||||||
@@ -556,6 +568,7 @@ namespace Netch.Forms
|
|||||||
MenuStrip.Enabled = ConfigurationGroupBox.Enabled = ControlButton.Enabled = SettingsButton.Enabled = true;
|
MenuStrip.Enabled = ConfigurationGroupBox.Enabled = ControlButton.Enabled = SettingsButton.Enabled = true;
|
||||||
ControlButton.Text = Utils.i18N.Translate("Start");
|
ControlButton.Text = Utils.i18N.Translate("Start");
|
||||||
MainController.Stop();
|
MainController.Stop();
|
||||||
|
NatTypeStatusLabel.Text = "";
|
||||||
}
|
}
|
||||||
Utils.Configuration.Save();
|
Utils.Configuration.Save();
|
||||||
}).ContinueWith(task =>
|
}).ContinueWith(task =>
|
||||||
@@ -759,6 +772,7 @@ namespace Netch.Forms
|
|||||||
|
|
||||||
private void ControlButton_Click(object sender, EventArgs e)
|
private void ControlButton_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
SaveConfigs();
|
||||||
if (State == Models.State.Waiting || State == Models.State.Stopped)
|
if (State == Models.State.Waiting || State == Models.State.Stopped)
|
||||||
{
|
{
|
||||||
// 当前 ServerComboBox 中至少有一项
|
// 当前 ServerComboBox 中至少有一项
|
||||||
@@ -786,7 +800,10 @@ namespace Netch.Forms
|
|||||||
var mode = ModeComboBox.SelectedItem as Models.Mode;
|
var mode = ModeComboBox.SelectedItem as Models.Mode;
|
||||||
|
|
||||||
MainController = new MainController();
|
MainController = new MainController();
|
||||||
if (MainController.Start(server, mode))
|
|
||||||
|
var startResult = MainController.Start(server, mode);
|
||||||
|
|
||||||
|
if (startResult)
|
||||||
{
|
{
|
||||||
// UsedBandwidthLabel.Visible = UploadSpeedLabel.Visible = DownloadSpeedLabel.Visible = true;
|
// UsedBandwidthLabel.Visible = UploadSpeedLabel.Visible = DownloadSpeedLabel.Visible = true;
|
||||||
// MainController.pNFController.OnBandwidthUpdated += OnBandwidthUpdated;
|
// MainController.pNFController.OnBandwidthUpdated += OnBandwidthUpdated;
|
||||||
@@ -883,6 +900,7 @@ namespace Netch.Forms
|
|||||||
var mode = ModeComboBox.SelectedItem as Models.Mode;
|
var mode = ModeComboBox.SelectedItem as Models.Mode;
|
||||||
|
|
||||||
MainController.Stop();
|
MainController.Stop();
|
||||||
|
NatTypeStatusLabel.Text = "";
|
||||||
|
|
||||||
// LastUploadBandwidth = 0;
|
// LastUploadBandwidth = 0;
|
||||||
// LastDownloadBandwidth = 0;
|
// LastDownloadBandwidth = 0;
|
||||||
@@ -1201,5 +1219,13 @@ namespace Netch.Forms
|
|||||||
MessageBox.Show(Utils.i18N.Translate("Please select a server first"), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
|
MessageBox.Show(Utils.i18N.Translate("Please select a server first"), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public void StatusText(string text)
|
||||||
|
{
|
||||||
|
StatusLabel.Text = text;
|
||||||
|
}
|
||||||
|
public void NatTypeStatusText(string text)
|
||||||
|
{
|
||||||
|
NatTypeStatusLabel.Text = "NatType:" + text;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
77
Netch/Forms/SettingForm.Designer.cs
generated
77
Netch/Forms/SettingForm.Designer.cs
generated
@@ -30,8 +30,6 @@
|
|||||||
{
|
{
|
||||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(SettingForm));
|
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(SettingForm));
|
||||||
this.PortGroupBox = new System.Windows.Forms.GroupBox();
|
this.PortGroupBox = new System.Windows.Forms.GroupBox();
|
||||||
this.RedirectorLabel = new System.Windows.Forms.Label();
|
|
||||||
this.RedirectorTextBox = new System.Windows.Forms.TextBox();
|
|
||||||
this.AllowDevicesCheckBox = new System.Windows.Forms.CheckBox();
|
this.AllowDevicesCheckBox = new System.Windows.Forms.CheckBox();
|
||||||
this.HTTPPortLabel = new System.Windows.Forms.Label();
|
this.HTTPPortLabel = new System.Windows.Forms.Label();
|
||||||
this.HTTPPortTextBox = new System.Windows.Forms.TextBox();
|
this.HTTPPortTextBox = new System.Windows.Forms.TextBox();
|
||||||
@@ -50,7 +48,11 @@
|
|||||||
this.ControlButton = new System.Windows.Forms.Button();
|
this.ControlButton = new System.Windows.Forms.Button();
|
||||||
this.GlobalBypassIPsButton = new System.Windows.Forms.Button();
|
this.GlobalBypassIPsButton = new System.Windows.Forms.Button();
|
||||||
this.BehaviorGroupBox = new System.Windows.Forms.GroupBox();
|
this.BehaviorGroupBox = new System.Windows.Forms.GroupBox();
|
||||||
|
this.STUN_ServerPortTextBox = new System.Windows.Forms.TextBox();
|
||||||
|
this.label2 = new System.Windows.Forms.Label();
|
||||||
|
this.label1 = new System.Windows.Forms.Label();
|
||||||
this.RunAtStartup = new System.Windows.Forms.CheckBox();
|
this.RunAtStartup = new System.Windows.Forms.CheckBox();
|
||||||
|
this.STUN_ServerTextBox = new System.Windows.Forms.TextBox();
|
||||||
this.MinimizeWhenStartedCheckBox = new System.Windows.Forms.CheckBox();
|
this.MinimizeWhenStartedCheckBox = new System.Windows.Forms.CheckBox();
|
||||||
this.ProfileCount_Label = new System.Windows.Forms.Label();
|
this.ProfileCount_Label = new System.Windows.Forms.Label();
|
||||||
this.ProfileCount_TextBox = new System.Windows.Forms.TextBox();
|
this.ProfileCount_TextBox = new System.Windows.Forms.TextBox();
|
||||||
@@ -65,8 +67,6 @@
|
|||||||
//
|
//
|
||||||
// PortGroupBox
|
// PortGroupBox
|
||||||
//
|
//
|
||||||
this.PortGroupBox.Controls.Add(this.RedirectorLabel);
|
|
||||||
this.PortGroupBox.Controls.Add(this.RedirectorTextBox);
|
|
||||||
this.PortGroupBox.Controls.Add(this.AllowDevicesCheckBox);
|
this.PortGroupBox.Controls.Add(this.AllowDevicesCheckBox);
|
||||||
this.PortGroupBox.Controls.Add(this.HTTPPortLabel);
|
this.PortGroupBox.Controls.Add(this.HTTPPortLabel);
|
||||||
this.PortGroupBox.Controls.Add(this.HTTPPortTextBox);
|
this.PortGroupBox.Controls.Add(this.HTTPPortTextBox);
|
||||||
@@ -79,23 +79,6 @@
|
|||||||
this.PortGroupBox.TabStop = false;
|
this.PortGroupBox.TabStop = false;
|
||||||
this.PortGroupBox.Text = "Local Port";
|
this.PortGroupBox.Text = "Local Port";
|
||||||
//
|
//
|
||||||
// RedirectorLabel
|
|
||||||
//
|
|
||||||
this.RedirectorLabel.AutoSize = true;
|
|
||||||
this.RedirectorLabel.Location = new System.Drawing.Point(9, 110);
|
|
||||||
this.RedirectorLabel.Name = "RedirectorLabel";
|
|
||||||
this.RedirectorLabel.Size = new System.Drawing.Size(95, 17);
|
|
||||||
this.RedirectorLabel.TabIndex = 6;
|
|
||||||
this.RedirectorLabel.Text = "Redirector TCP";
|
|
||||||
//
|
|
||||||
// RedirectorTextBox
|
|
||||||
//
|
|
||||||
this.RedirectorTextBox.Location = new System.Drawing.Point(120, 107);
|
|
||||||
this.RedirectorTextBox.Name = "RedirectorTextBox";
|
|
||||||
this.RedirectorTextBox.Size = new System.Drawing.Size(294, 23);
|
|
||||||
this.RedirectorTextBox.TabIndex = 7;
|
|
||||||
this.RedirectorTextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
|
|
||||||
//
|
|
||||||
// AllowDevicesCheckBox
|
// AllowDevicesCheckBox
|
||||||
//
|
//
|
||||||
this.AllowDevicesCheckBox.AutoSize = true;
|
this.AllowDevicesCheckBox.AutoSize = true;
|
||||||
@@ -241,7 +224,7 @@
|
|||||||
// ControlButton
|
// ControlButton
|
||||||
//
|
//
|
||||||
this.ControlButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
this.ControlButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||||
this.ControlButton.Location = new System.Drawing.Point(357, 549);
|
this.ControlButton.Location = new System.Drawing.Point(357, 648);
|
||||||
this.ControlButton.Name = "ControlButton";
|
this.ControlButton.Name = "ControlButton";
|
||||||
this.ControlButton.Size = new System.Drawing.Size(75, 23);
|
this.ControlButton.Size = new System.Drawing.Size(75, 23);
|
||||||
this.ControlButton.TabIndex = 11;
|
this.ControlButton.TabIndex = 11;
|
||||||
@@ -252,7 +235,7 @@
|
|||||||
// GlobalBypassIPsButton
|
// GlobalBypassIPsButton
|
||||||
//
|
//
|
||||||
this.GlobalBypassIPsButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
this.GlobalBypassIPsButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||||
this.GlobalBypassIPsButton.Location = new System.Drawing.Point(12, 549);
|
this.GlobalBypassIPsButton.Location = new System.Drawing.Point(12, 648);
|
||||||
this.GlobalBypassIPsButton.Name = "GlobalBypassIPsButton";
|
this.GlobalBypassIPsButton.Name = "GlobalBypassIPsButton";
|
||||||
this.GlobalBypassIPsButton.Size = new System.Drawing.Size(128, 23);
|
this.GlobalBypassIPsButton.Size = new System.Drawing.Size(128, 23);
|
||||||
this.GlobalBypassIPsButton.TabIndex = 10;
|
this.GlobalBypassIPsButton.TabIndex = 10;
|
||||||
@@ -262,7 +245,11 @@
|
|||||||
//
|
//
|
||||||
// BehaviorGroupBox
|
// BehaviorGroupBox
|
||||||
//
|
//
|
||||||
|
this.BehaviorGroupBox.Controls.Add(this.STUN_ServerPortTextBox);
|
||||||
|
this.BehaviorGroupBox.Controls.Add(this.label2);
|
||||||
|
this.BehaviorGroupBox.Controls.Add(this.label1);
|
||||||
this.BehaviorGroupBox.Controls.Add(this.RunAtStartup);
|
this.BehaviorGroupBox.Controls.Add(this.RunAtStartup);
|
||||||
|
this.BehaviorGroupBox.Controls.Add(this.STUN_ServerTextBox);
|
||||||
this.BehaviorGroupBox.Controls.Add(this.MinimizeWhenStartedCheckBox);
|
this.BehaviorGroupBox.Controls.Add(this.MinimizeWhenStartedCheckBox);
|
||||||
this.BehaviorGroupBox.Controls.Add(this.ProfileCount_Label);
|
this.BehaviorGroupBox.Controls.Add(this.ProfileCount_Label);
|
||||||
this.BehaviorGroupBox.Controls.Add(this.ProfileCount_TextBox);
|
this.BehaviorGroupBox.Controls.Add(this.ProfileCount_TextBox);
|
||||||
@@ -272,11 +259,37 @@
|
|||||||
this.BehaviorGroupBox.Controls.Add(this.ExitWhenClosedCheckBox);
|
this.BehaviorGroupBox.Controls.Add(this.ExitWhenClosedCheckBox);
|
||||||
this.BehaviorGroupBox.Location = new System.Drawing.Point(12, 330);
|
this.BehaviorGroupBox.Location = new System.Drawing.Point(12, 330);
|
||||||
this.BehaviorGroupBox.Name = "BehaviorGroupBox";
|
this.BehaviorGroupBox.Name = "BehaviorGroupBox";
|
||||||
this.BehaviorGroupBox.Size = new System.Drawing.Size(420, 213);
|
this.BehaviorGroupBox.Size = new System.Drawing.Size(420, 312);
|
||||||
this.BehaviorGroupBox.TabIndex = 8;
|
this.BehaviorGroupBox.TabIndex = 8;
|
||||||
this.BehaviorGroupBox.TabStop = false;
|
this.BehaviorGroupBox.TabStop = false;
|
||||||
this.BehaviorGroupBox.Text = "Behavior";
|
this.BehaviorGroupBox.Text = "Behavior";
|
||||||
//
|
//
|
||||||
|
// STUN_ServerPortTextBox
|
||||||
|
//
|
||||||
|
this.STUN_ServerPortTextBox.Location = new System.Drawing.Point(120, 237);
|
||||||
|
this.STUN_ServerPortTextBox.Name = "STUN_ServerPortTextBox";
|
||||||
|
this.STUN_ServerPortTextBox.Size = new System.Drawing.Size(294, 23);
|
||||||
|
this.STUN_ServerPortTextBox.TabIndex = 8;
|
||||||
|
this.STUN_ServerPortTextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
|
||||||
|
//
|
||||||
|
// label2
|
||||||
|
//
|
||||||
|
this.label2.AutoSize = true;
|
||||||
|
this.label2.Location = new System.Drawing.Point(9, 243);
|
||||||
|
this.label2.Name = "label2";
|
||||||
|
this.label2.Size = new System.Drawing.Size(110, 17);
|
||||||
|
this.label2.TabIndex = 12;
|
||||||
|
this.label2.Text = "STUN Server Port";
|
||||||
|
//
|
||||||
|
// label1
|
||||||
|
//
|
||||||
|
this.label1.AutoSize = true;
|
||||||
|
this.label1.Location = new System.Drawing.Point(9, 214);
|
||||||
|
this.label1.Name = "label1";
|
||||||
|
this.label1.Size = new System.Drawing.Size(82, 17);
|
||||||
|
this.label1.TabIndex = 10;
|
||||||
|
this.label1.Text = "STUN Server";
|
||||||
|
//
|
||||||
// RunAtStartup
|
// RunAtStartup
|
||||||
//
|
//
|
||||||
this.RunAtStartup.AutoSize = true;
|
this.RunAtStartup.AutoSize = true;
|
||||||
@@ -287,6 +300,14 @@
|
|||||||
this.RunAtStartup.Text = "Run at startup";
|
this.RunAtStartup.Text = "Run at startup";
|
||||||
this.RunAtStartup.UseVisualStyleBackColor = true;
|
this.RunAtStartup.UseVisualStyleBackColor = true;
|
||||||
//
|
//
|
||||||
|
// STUN_ServerTextBox
|
||||||
|
//
|
||||||
|
this.STUN_ServerTextBox.Location = new System.Drawing.Point(120, 211);
|
||||||
|
this.STUN_ServerTextBox.Name = "STUN_ServerTextBox";
|
||||||
|
this.STUN_ServerTextBox.Size = new System.Drawing.Size(294, 23);
|
||||||
|
this.STUN_ServerTextBox.TabIndex = 11;
|
||||||
|
this.STUN_ServerTextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
|
||||||
|
//
|
||||||
// MinimizeWhenStartedCheckBox
|
// MinimizeWhenStartedCheckBox
|
||||||
//
|
//
|
||||||
this.MinimizeWhenStartedCheckBox.AutoSize = true;
|
this.MinimizeWhenStartedCheckBox.AutoSize = true;
|
||||||
@@ -362,7 +383,7 @@
|
|||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
|
||||||
this.ClientSize = new System.Drawing.Size(444, 583);
|
this.ClientSize = new System.Drawing.Size(444, 682);
|
||||||
this.Controls.Add(this.BehaviorGroupBox);
|
this.Controls.Add(this.BehaviorGroupBox);
|
||||||
this.Controls.Add(this.PortGroupBox);
|
this.Controls.Add(this.PortGroupBox);
|
||||||
this.Controls.Add(this.GlobalBypassIPsButton);
|
this.Controls.Add(this.GlobalBypassIPsButton);
|
||||||
@@ -408,8 +429,6 @@
|
|||||||
private System.Windows.Forms.Button GlobalBypassIPsButton;
|
private System.Windows.Forms.Button GlobalBypassIPsButton;
|
||||||
private System.Windows.Forms.CheckBox TUNTAPUseCustomDNSCheckBox;
|
private System.Windows.Forms.CheckBox TUNTAPUseCustomDNSCheckBox;
|
||||||
private System.Windows.Forms.CheckBox AllowDevicesCheckBox;
|
private System.Windows.Forms.CheckBox AllowDevicesCheckBox;
|
||||||
private System.Windows.Forms.TextBox RedirectorTextBox;
|
|
||||||
private System.Windows.Forms.Label RedirectorLabel;
|
|
||||||
private System.Windows.Forms.GroupBox BehaviorGroupBox;
|
private System.Windows.Forms.GroupBox BehaviorGroupBox;
|
||||||
private System.Windows.Forms.CheckBox ExitWhenClosedCheckBox;
|
private System.Windows.Forms.CheckBox ExitWhenClosedCheckBox;
|
||||||
private System.Windows.Forms.CheckBox StopWhenExitedCheckBox;
|
private System.Windows.Forms.CheckBox StopWhenExitedCheckBox;
|
||||||
@@ -419,5 +438,9 @@
|
|||||||
private System.Windows.Forms.TextBox ProfileCount_TextBox;
|
private System.Windows.Forms.TextBox ProfileCount_TextBox;
|
||||||
private System.Windows.Forms.CheckBox MinimizeWhenStartedCheckBox;
|
private System.Windows.Forms.CheckBox MinimizeWhenStartedCheckBox;
|
||||||
private System.Windows.Forms.CheckBox RunAtStartup;
|
private System.Windows.Forms.CheckBox RunAtStartup;
|
||||||
|
private System.Windows.Forms.Label label2;
|
||||||
|
private System.Windows.Forms.Label label1;
|
||||||
|
private System.Windows.Forms.TextBox STUN_ServerTextBox;
|
||||||
|
private System.Windows.Forms.TextBox STUN_ServerPortTextBox;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -64,7 +64,6 @@ namespace Netch.Forms
|
|||||||
|
|
||||||
Socks5PortTextBox.Text = Global.Settings.Socks5LocalPort.ToString();
|
Socks5PortTextBox.Text = Global.Settings.Socks5LocalPort.ToString();
|
||||||
HTTPPortTextBox.Text = Global.Settings.HTTPLocalPort.ToString();
|
HTTPPortTextBox.Text = Global.Settings.HTTPLocalPort.ToString();
|
||||||
RedirectorTextBox.Text = Global.Settings.RedirectorTCPPort.ToString();
|
|
||||||
|
|
||||||
TUNTAPAddressTextBox.Text = Global.Settings.TUNTAP.Address;
|
TUNTAPAddressTextBox.Text = Global.Settings.TUNTAP.Address;
|
||||||
TUNTAPNetmaskTextBox.Text = Global.Settings.TUNTAP.Netmask;
|
TUNTAPNetmaskTextBox.Text = Global.Settings.TUNTAP.Netmask;
|
||||||
@@ -82,6 +81,8 @@ namespace Netch.Forms
|
|||||||
ProfileCount_Label.Text = Utils.i18N.Translate(ProfileCount_Label.Text);
|
ProfileCount_Label.Text = Utils.i18N.Translate(ProfileCount_Label.Text);
|
||||||
|
|
||||||
ProfileCount_TextBox.Text = Global.Settings.ProfileCount.ToString();
|
ProfileCount_TextBox.Text = Global.Settings.ProfileCount.ToString();
|
||||||
|
STUN_ServerTextBox.Text = Global.Settings.STUN_Server.ToString();
|
||||||
|
STUN_ServerPortTextBox.Text = Global.Settings.STUN_Server_Port.ToString();
|
||||||
|
|
||||||
if (Global.Settings.TUNTAP.DNS.Count > 0)
|
if (Global.Settings.TUNTAP.DNS.Count > 0)
|
||||||
{
|
{
|
||||||
@@ -223,27 +224,6 @@ namespace Netch.Forms
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var RedirectorPort = int.Parse(RedirectorTextBox.Text);
|
|
||||||
|
|
||||||
if (RedirectorPort > 0 && RedirectorPort < 65536)
|
|
||||||
{
|
|
||||||
Global.Settings.RedirectorTCPPort = RedirectorPort;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new FormatException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (FormatException)
|
|
||||||
{
|
|
||||||
RedirectorTextBox.Text = Global.Settings.RedirectorTCPPort.ToString();
|
|
||||||
MessageBox.Show(Utils.i18N.Translate("Port value illegal. Try again."), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (AllowDevicesCheckBox.Checked)
|
if (AllowDevicesCheckBox.Checked)
|
||||||
{
|
{
|
||||||
Global.Settings.LocalAddress = "0.0.0.0";
|
Global.Settings.LocalAddress = "0.0.0.0";
|
||||||
@@ -289,7 +269,7 @@ namespace Netch.Forms
|
|||||||
{
|
{
|
||||||
var ProfileCount = int.Parse(ProfileCount_TextBox.Text);
|
var ProfileCount = int.Parse(ProfileCount_TextBox.Text);
|
||||||
|
|
||||||
if (ProfileCount>0)
|
if (ProfileCount > 0)
|
||||||
{
|
{
|
||||||
Global.Settings.ProfileCount = ProfileCount;
|
Global.Settings.ProfileCount = ProfileCount;
|
||||||
}
|
}
|
||||||
@@ -305,6 +285,29 @@ namespace Netch.Forms
|
|||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var STUN_Server = STUN_ServerTextBox.Text;
|
||||||
|
Global.Settings.STUN_Server = STUN_Server;
|
||||||
|
|
||||||
|
var STUN_ServerPort = int.Parse(STUN_ServerPortTextBox.Text);
|
||||||
|
|
||||||
|
if (STUN_ServerPort > 0)
|
||||||
|
{
|
||||||
|
Global.Settings.STUN_Server_Port = STUN_ServerPort;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new FormatException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (FormatException)
|
||||||
|
{
|
||||||
|
ProfileCount_TextBox.Text = Global.Settings.ProfileCount.ToString();
|
||||||
|
MessageBox.Show(Utils.i18N.Translate("STUN_ServerPort value illegal. Try again."), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Global.Settings.TUNTAP.Address = TUNTAPAddressTextBox.Text;
|
Global.Settings.TUNTAP.Address = TUNTAPAddressTextBox.Text;
|
||||||
Global.Settings.TUNTAP.Netmask = TUNTAPNetmaskTextBox.Text;
|
Global.Settings.TUNTAP.Netmask = TUNTAPNetmaskTextBox.Text;
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ namespace Netch.Models
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Redirector TCP 占用端口
|
/// Redirector TCP 占用端口
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int RedirectorTCPPort = 2800;
|
//public int RedirectorTCPPort = 2800;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// HTTP 和 Socks5 本地代理地址
|
/// HTTP 和 Socks5 本地代理地址
|
||||||
@@ -127,7 +127,7 @@ namespace Netch.Models
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 全局绕过 IP 列表
|
/// 全局绕过 IP 列表
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public List<string> BypassIPs = new List<string>();
|
public List<string> BypassIPs = new List<string>() { "10.0.0.0/8", "172.16.0.0/16", "192.168.0.0/24" };
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 已保存的快捷配置
|
/// 已保存的快捷配置
|
||||||
@@ -138,5 +138,15 @@ namespace Netch.Models
|
|||||||
/// 快捷配置数量
|
/// 快捷配置数量
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int ProfileCount = 4;
|
public int ProfileCount = 4;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// STUN测试服务器
|
||||||
|
/// </summary>
|
||||||
|
public string STUN_Server = "stun.stunprotocol.org";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// STUN测试服务器
|
||||||
|
/// </summary>
|
||||||
|
public int STUN_Server_Port = 3478;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,6 +65,8 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="DNS" Version="5.0.0" />
|
||||||
|
<PackageReference Include="DnsClient" Version="1.2.0" />
|
||||||
<PackageReference Include="ini-parser" Version="2.5.2" />
|
<PackageReference Include="ini-parser" Version="2.5.2" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||||
<PackageReference Include="System.Buffers" Version="4.5.0" />
|
<PackageReference Include="System.Buffers" Version="4.5.0" />
|
||||||
|
|||||||
59
Netch/Resolver.cs
Normal file
59
Netch/Resolver.cs
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
using DNS.Protocol;
|
||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Netch
|
||||||
|
{
|
||||||
|
public class Resolver : DNS.Client.RequestResolver.IRequestResolver
|
||||||
|
{
|
||||||
|
public Task<IResponse> Resolve(IRequest request)
|
||||||
|
{
|
||||||
|
IResponse response = Response.FromRequest(request);
|
||||||
|
|
||||||
|
foreach (var question in response.Questions)
|
||||||
|
{
|
||||||
|
if (question.Type == RecordType.A)
|
||||||
|
{
|
||||||
|
var client = new DnsClient.LookupClient(DnsClient.NameServer.GooglePublicDns);
|
||||||
|
client.UseTcpOnly = true;
|
||||||
|
client.UseCache = true;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var result = client.Query(question.Name.ToString(), DnsClient.QueryType.A);
|
||||||
|
foreach (var item in result.Answers.ARecords())
|
||||||
|
{
|
||||||
|
response.AnswerRecords.Add(new DNS.Protocol.ResourceRecords.IPAddressResourceRecord(question.Name, item.Address));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
// 跳过
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (question.Type == RecordType.AAAA)
|
||||||
|
{
|
||||||
|
var client = new DnsClient.LookupClient(DnsClient.NameServer.GooglePublicDns);
|
||||||
|
client.UseTcpOnly = true;
|
||||||
|
client.UseCache = true;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var result = client.Query(question.Name.ToString(), DnsClient.QueryType.AAAA);
|
||||||
|
foreach (var item in result.Answers.AaaaRecords())
|
||||||
|
{
|
||||||
|
response.AnswerRecords.Add(new DNS.Protocol.ResourceRecords.IPAddressResourceRecord(question.Name, item.Address));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
// 跳过
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Task.FromResult(response);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -16,6 +16,16 @@
|
|||||||
"Started": "已启动",
|
"Started": "已启动",
|
||||||
"Stopping": "正在停止中",
|
"Stopping": "正在停止中",
|
||||||
"Stopped": "已停止",
|
"Stopped": "已停止",
|
||||||
|
"Starting Shadowsocks": "正在启动Shadowsocks",
|
||||||
|
"Starting ShadowsocksR": "正在启动ShadowsocksR",
|
||||||
|
"Starting V2ray": "正在启动V2ray",
|
||||||
|
"Starting Tap": "正在启动Tap",
|
||||||
|
"Starting NatTester": "正在启动Nat测试",
|
||||||
|
"Starting LocalDns service": "正在启动本地DNS服务",
|
||||||
|
"Starting Redirector": "正在启动Redirector",
|
||||||
|
"Starting netfilter2 Service": "正在启动netfilter2服务",
|
||||||
|
"Starting dns2tcp Service": "正在启动dns2tcp服务",
|
||||||
|
"SetupBypass": "设置绕行规则",
|
||||||
|
|
||||||
"Server": "服务器",
|
"Server": "服务器",
|
||||||
"Import Servers From Clipboard": "从剪贴板导入服务器",
|
"Import Servers From Clipboard": "从剪贴板导入服务器",
|
||||||
@@ -134,6 +144,7 @@
|
|||||||
"Check update when opened": "打开软件时检查更新",
|
"Check update when opened": "打开软件时检查更新",
|
||||||
"ProfileCount": "快捷配置数量(重启软件生效)",
|
"ProfileCount": "快捷配置数量(重启软件生效)",
|
||||||
"ProfileCount value illegal. Try again.": "快捷配置数值非法。请重试。",
|
"ProfileCount value illegal. Try again.": "快捷配置数值非法。请重试。",
|
||||||
|
"STUN_ServerPort value illegal. Try again.": "STUN端口数值非法。请重试。",
|
||||||
"TUN/TAP driver is not detected. Is it installed now?": "未检测到TUN/TAP驱动,是否现在安装?",
|
"TUN/TAP driver is not detected. Is it installed now?": "未检测到TUN/TAP驱动,是否现在安装?",
|
||||||
|
|
||||||
"Profile": "配置名",
|
"Profile": "配置名",
|
||||||
|
|||||||
@@ -109,39 +109,45 @@ namespace Netch.Utils
|
|||||||
var AddressGot = false;
|
var AddressGot = false;
|
||||||
foreach (var adapter in NetworkInterface.GetAllNetworkInterfaces())
|
foreach (var adapter in NetworkInterface.GetAllNetworkInterfaces())
|
||||||
{
|
{
|
||||||
var adapterProperties = adapter.GetIPProperties();
|
try
|
||||||
var p = adapterProperties.GetIPv4Properties();
|
|
||||||
Logging.Info($"检测适配器:{adapter.Name} {adapter.Id} {adapter.Description}, index: {p.Index}");
|
|
||||||
|
|
||||||
// 通过索引查找对应适配器的 IPv4 地址
|
|
||||||
if (p.Index == Global.Adapter.Index)
|
|
||||||
{
|
{
|
||||||
var AdapterIPs = "";
|
var adapterProperties = adapter.GetIPProperties();
|
||||||
|
var p = adapterProperties.GetIPv4Properties();
|
||||||
|
Logging.Info($"检测适配器:{adapter.Name} {adapter.Id} {adapter.Description}, index: {p.Index}");
|
||||||
|
|
||||||
foreach (var ip in adapterProperties.UnicastAddresses)
|
// 通过索引查找对应适配器的 IPv4 地址
|
||||||
|
if (p.Index == Global.Adapter.Index)
|
||||||
{
|
{
|
||||||
if (ip.Address.AddressFamily == AddressFamily.InterNetwork)
|
var AdapterIPs = "";
|
||||||
|
|
||||||
|
foreach (var ip in adapterProperties.UnicastAddresses)
|
||||||
{
|
{
|
||||||
AddressGot = true;
|
if (ip.Address.AddressFamily == AddressFamily.InterNetwork)
|
||||||
Global.Adapter.Address = ip.Address;
|
{
|
||||||
Logging.Info($"当前出口 IPv4 地址:{Global.Adapter.Address}");
|
AddressGot = true;
|
||||||
break;
|
Global.Adapter.Address = ip.Address;
|
||||||
|
Logging.Info($"当前出口 IPv4 地址:{Global.Adapter.Address}");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
AdapterIPs = $"{ip.Address} | ";
|
||||||
}
|
}
|
||||||
AdapterIPs = $"{ip.Address} | ";
|
|
||||||
|
if (!AddressGot)
|
||||||
|
{
|
||||||
|
if (AdapterIPs.Length > 3)
|
||||||
|
{
|
||||||
|
AdapterIPs = AdapterIPs.Substring(0, AdapterIPs.Length - 3);
|
||||||
|
Logging.Info($"所有出口地址:{AdapterIPs}");
|
||||||
|
}
|
||||||
|
Logging.Info("出口无 IPv4 地址,当前只支持 IPv4 地址");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!AddressGot)
|
|
||||||
{
|
|
||||||
if (AdapterIPs.Length > 3)
|
|
||||||
{
|
|
||||||
AdapterIPs = AdapterIPs.Substring(0, AdapterIPs.Length - 3);
|
|
||||||
Logging.Info($"所有出口地址:{AdapterIPs}");
|
|
||||||
}
|
|
||||||
Logging.Info("出口无 IPv4 地址,当前只支持 IPv4 地址");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{ }
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!AddressGot)
|
if (!AddressGot)
|
||||||
|
|||||||
2
binaries
2
binaries
Submodule binaries updated: ab7f65c101...8dfd5beec9
2
modes
2
modes
Submodule modes updated: 9b3ce74bd6...8d6f98d43e
Reference in New Issue
Block a user