mirror of
https://github.com/netchx/netch.git
synced 2026-03-18 18:13:21 +08:00
🎨 tap模式内置dns改为dns2tcp处理
This commit is contained in:
@@ -1,12 +1,85 @@
|
||||
using Netch.Forms;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Threading;
|
||||
|
||||
namespace Netch.Controllers
|
||||
{
|
||||
public class DNSController
|
||||
{
|
||||
public static DNS.Server.DnsServer Server = new DNS.Server.DnsServer(new Resolver());
|
||||
/// <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()
|
||||
{
|
||||
@@ -34,6 +107,6 @@ namespace Netch.Controllers
|
||||
{
|
||||
Utils.Logging.Info(e.ToString());
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
@@ -300,7 +300,7 @@ namespace Netch.Controllers
|
||||
else
|
||||
{
|
||||
pDNSController.Start();
|
||||
dns = "127.0.0.1";
|
||||
dns = "127.0.0.1,127.0.0.1";
|
||||
//dns = "1.1.1.1,1.0.0.1";
|
||||
}
|
||||
|
||||
@@ -362,6 +362,7 @@ namespace Netch.Controllers
|
||||
//pDNSController.Stop();
|
||||
//修复点击停止按钮后再启动,DNS服务没监听的BUG
|
||||
ClearBypass();
|
||||
pDNSController.Stop();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
"Starting LocalDns service": "正在启动本地DNS服务",
|
||||
"Starting Redirector": "正在启动Redirector",
|
||||
"Starting netfilter2 Service": "正在启动netfilter2服务",
|
||||
"Starting dns2tcp Service": "正在启动dns2tcp服务",
|
||||
"SetupBypass": "设置绕行规则",
|
||||
|
||||
"Server": "服务器",
|
||||
|
||||
Reference in New Issue
Block a user