mirror of
https://github.com/netchx/netch.git
synced 2026-04-03 19:35:10 +08:00
replace unbound dns with aiodns
This commit is contained in:
@@ -1,12 +1,15 @@
|
||||
namespace Netch.Controllers
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace Netch.Controllers
|
||||
{
|
||||
public class DNSController : Controller
|
||||
{
|
||||
public DNSController()
|
||||
{
|
||||
Name = "DNS Service";
|
||||
MainFile = "unbound.exe";
|
||||
// RedirectStd = false;
|
||||
RedirectStd = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -15,12 +18,31 @@
|
||||
/// <returns></returns>
|
||||
public bool Start()
|
||||
{
|
||||
return StartInstanceAuto("-c unbound-service.conf -v");
|
||||
if (!aiodns_dial(Encoding.UTF8.GetBytes(Path.GetFullPath("bin\\china_site_list")),
|
||||
Encoding.UTF8.GetBytes("223.5.5.5:53"),
|
||||
Encoding.UTF8.GetBytes("1.1.1.1:53"))
|
||||
)
|
||||
return false;
|
||||
return
|
||||
aiodns_init();
|
||||
}
|
||||
|
||||
public override void Stop()
|
||||
{
|
||||
StopInstance();
|
||||
aiodns_free();
|
||||
}
|
||||
|
||||
#region NativeMethods
|
||||
|
||||
[DllImport("aiodns.bin", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern bool aiodns_dial(byte[] chinacon, byte[] chinadns, byte[] otherdns);
|
||||
|
||||
[DllImport("aiodns.bin", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern bool aiodns_init();
|
||||
|
||||
[DllImport("aiodns.bin", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void aiodns_free();
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.ServiceProcess;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@@ -62,18 +63,18 @@ namespace Netch.Controllers
|
||||
return false;
|
||||
}
|
||||
|
||||
NativeMethods.aio_dial((int) NameList.TYPE_CLRNAME, "");
|
||||
aio_dial((int) NameList.TYPE_CLRNAME, "");
|
||||
foreach (var rule in mode.Rule)
|
||||
{
|
||||
NativeMethods.aio_dial((int) NameList.TYPE_ADDNAME, rule);
|
||||
aio_dial((int) NameList.TYPE_ADDNAME, rule);
|
||||
}
|
||||
|
||||
NativeMethods.aio_dial((int) NameList.TYPE_ADDNAME, "NTT.exe");
|
||||
aio_dial((int) NameList.TYPE_ADDNAME, "NTT.exe");
|
||||
|
||||
if (server.Type != "Socks5")
|
||||
{
|
||||
NativeMethods.aio_dial((int) NameList.TYPE_TCPHOST, $"127.0.0.1:{Global.Settings.Socks5LocalPort}");
|
||||
NativeMethods.aio_dial((int) NameList.TYPE_UDPHOST, $"127.0.0.1:{Global.Settings.Socks5LocalPort}");
|
||||
aio_dial((int) NameList.TYPE_TCPHOST, $"127.0.0.1:{Global.Settings.Socks5LocalPort}");
|
||||
aio_dial((int) NameList.TYPE_UDPHOST, $"127.0.0.1:{Global.Settings.Socks5LocalPort}");
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -84,8 +85,8 @@ namespace Netch.Controllers
|
||||
return false;
|
||||
}
|
||||
|
||||
NativeMethods.aio_dial((int) NameList.TYPE_TCPHOST, $"{result}:{server.Port}");
|
||||
NativeMethods.aio_dial((int) NameList.TYPE_UDPHOST, $"{result}:{server.Port}");
|
||||
aio_dial((int) NameList.TYPE_TCPHOST, $"{result}:{server.Port}");
|
||||
aio_dial((int) NameList.TYPE_UDPHOST, $"{result}:{server.Port}");
|
||||
}
|
||||
|
||||
if (Global.Settings.ModifySystemDNS)
|
||||
@@ -96,7 +97,7 @@ namespace Netch.Controllers
|
||||
DNS.SetDNS(dns);
|
||||
}
|
||||
|
||||
return NativeMethods.aio_init();
|
||||
return aio_init();
|
||||
}
|
||||
|
||||
public override void Stop()
|
||||
@@ -108,9 +109,28 @@ namespace Netch.Controllers
|
||||
DNS.SetDNS(_sysDns);
|
||||
});
|
||||
|
||||
NativeMethods.aio_free();
|
||||
aio_free();
|
||||
}
|
||||
|
||||
#region NativeMethods
|
||||
|
||||
[DllImport("Redirector.bin", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern bool aio_dial(int name, [MarshalAs(UnmanagedType.LPWStr)] string value);
|
||||
|
||||
[DllImport("Redirector.bin", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern bool aio_init();
|
||||
|
||||
[DllImport("Redirector.bin", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern bool aio_free();
|
||||
|
||||
[DllImport("Redirector.bin", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern ulong aio_getUP();
|
||||
|
||||
[DllImport("Redirector.bin", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern ulong aio_getDL();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Utils
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user