Check whether tun2socks supports fakeDNS

This commit is contained in:
ChsBuffer
2020-09-21 21:27:54 +08:00
parent becc6d8187
commit b3f8b863e2
5 changed files with 49 additions and 4 deletions

View File

@@ -237,7 +237,7 @@ namespace Netch.Controllers
argument.Append(
$"-tunAddr {Global.Settings.TUNTAP.Address} -tunMask {Global.Settings.TUNTAP.Netmask} -tunGw {Global.Settings.TUNTAP.Gateway} -tunDns {dns} -tunName \"{adapterName}\" ");
if (Global.Settings.TUNTAP.UseFakeDNS)
if (Global.Settings.TUNTAP.UseFakeDNS && Global.SupportFakeDns)
argument.Append("-fakeDns ");
return StartInstanceAuto(argument.ToString(), ProcessPriorityClass.RealTime);
@@ -257,6 +257,40 @@ namespace Netch.Controllers
Task.WaitAll(tasks);
}
public bool TestFakeDNS()
{
var exited = false;
var helpStr = new StringBuilder();
try
{
void OnOutputDataReceived(object sender,DataReceivedEventArgs e)
{
if (e.Data == null)
{
exited = true;
return;
}
helpStr.Append(e.Data);
}
InitInstance("-h");
// Instance.OutputDataReceived += OnOutputDataReceived;
Instance.ErrorDataReceived += OnOutputDataReceived;
Instance.Start();
Instance.BeginOutputReadLine();
Instance.BeginErrorReadLine();
while (!exited)
{
Thread.Sleep(200);
}
return helpStr.ToString().Contains("-fakeDns");
}
catch
{
return false;
}
}
/// <summary>
/// 搜索出口和TUNTAP适配器
/// </summary>

View File

@@ -184,6 +184,7 @@
this.UseFakeDNSCheckBox.Size = new System.Drawing.Size(110, 21);
this.UseFakeDNSCheckBox.TabIndex = 11;
this.UseFakeDNSCheckBox.Text = "Use Fake DNS";
this.UseFakeDNSCheckBox.Visible = false;
this.UseFakeDNSCheckBox.UseVisualStyleBackColor = true;
//
// ProxyDNSCheckBox

View File

@@ -122,6 +122,7 @@ namespace Netch.Forms
private void SettingForm_Load(object sender, EventArgs e)
{
UseFakeDNSCheckBox.Visible = Global.SupportFakeDns;
InitText();
InitValue();
}

View File

@@ -24,6 +24,8 @@ namespace Netch
/// </summary>
public static MainForm MainForm;
public static bool SupportFakeDns = false;
/// <summary>
/// SS/SSR 加密方式
/// </summary>

View File

@@ -67,9 +67,16 @@ namespace Netch
}
Logging.Info($"版本: {UpdateChecker.Owner}/{UpdateChecker.Repo}@{UpdateChecker.Version}");
Task.Run(() => { Logging.Info($"主程序 SHA256: {Utils.Utils.SHA256CheckSum(Application.ExecutablePath)}"); });
Logging.Info("启动单实例");
Task.Run(OnlyInstance.Server);
Task.Run(() =>
{
Logging.Info($"主程序 SHA256: {Utils.Utils.SHA256CheckSum(Application.ExecutablePath)}");
});
Task.Run(() =>
{
Logging.Info("启动单实例");
OnlyInstance.Server();
});
Task.Run(() => { Global.SupportFakeDns = new TUNTAPController().TestFakeDNS(); });
// 绑定错误捕获
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);