mirror of
https://github.com/netchx/netch.git
synced 2026-05-11 23:45:06 +08:00
[Netch] Updated
This commit is contained in:
@@ -21,31 +21,23 @@ namespace Netch.Controllers
|
||||
case Models.Server.ServerType.Socks:
|
||||
break;
|
||||
case Models.Server.ServerType.Shadowsocks:
|
||||
{
|
||||
if (m.Type == Models.Mode.ModeType.ProcessMode)
|
||||
{
|
||||
var node = s as Models.Server.Shadowsocks.Shadowsocks;
|
||||
if (String.IsNullOrEmpty(node.OBFS))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
this.NodeController = new Server.ShadowsocksController();
|
||||
}
|
||||
this.NodeController = new Server.ShadowsocksController();
|
||||
break;
|
||||
case Models.Server.ServerType.ShadowsocksR:
|
||||
this.NodeController = new Server.ShadowsocksRController();
|
||||
break;
|
||||
case Models.Server.ServerType.WireGuard:
|
||||
this.NodeController = new Server.WireGuardController();
|
||||
break;
|
||||
case Models.Server.ServerType.Trojan:
|
||||
this.NodeController = new Server.TrojanController();
|
||||
break;
|
||||
case Models.Server.ServerType.VLess:
|
||||
this.NodeController = new Server.VLessController();
|
||||
break;
|
||||
case Models.Server.ServerType.VMess:
|
||||
this.NodeController = new Server.VMessController();
|
||||
break;
|
||||
case Models.Server.ServerType.VLess:
|
||||
this.NodeController = new Server.VLessController();
|
||||
break;
|
||||
default:
|
||||
Global.Logger.Error($"未知的节点类型:{s.Type}");
|
||||
|
||||
@@ -63,23 +55,17 @@ namespace Netch.Controllers
|
||||
switch (m.Type)
|
||||
{
|
||||
case Models.Mode.ModeType.ProcessMode:
|
||||
this.ModeController = new Mode.RedirectorController();
|
||||
this.ModeController = new Mode.ProcessController();
|
||||
break;
|
||||
case Models.Mode.ModeType.ShareMode:
|
||||
this.ModeController = new Mode.ShareController();
|
||||
break;
|
||||
case Models.Mode.ModeType.TapMode:
|
||||
this.ModeController = new Mode.TapController();
|
||||
break;
|
||||
case Models.Mode.ModeType.TunMode:
|
||||
this.ModeController = new Mode.TunController();
|
||||
break;
|
||||
case Models.Mode.ModeType.WebMode:
|
||||
this.ModeController = new Mode.WebController();
|
||||
break;
|
||||
case Models.Mode.ModeType.WmpMode:
|
||||
this.ModeController = new Mode.WmpController();
|
||||
break;
|
||||
default:
|
||||
Global.Logger.Error($"未知的模式类型:{s.Type}");
|
||||
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace Netch.Controllers.Mode
|
||||
{
|
||||
public class LSPController : Interface.IController
|
||||
{
|
||||
public bool Create(Models.Server.Server s, Models.Mode.Mode m)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public bool Delete()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
96
Netch/Controllers/Mode/ProcessController.cs
Normal file
96
Netch/Controllers/Mode/ProcessController.cs
Normal file
@@ -0,0 +1,96 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Netch.Controllers.Mode
|
||||
{
|
||||
public class ProcessController : Interface.IController
|
||||
{
|
||||
private enum NameList : int
|
||||
{
|
||||
AIO_FILTERLOOPBACK,
|
||||
AIO_FILTERINTRANET,
|
||||
AIO_FILTERICMP,
|
||||
AIO_FILTERTCP,
|
||||
AIO_FILTERUDP,
|
||||
|
||||
AIO_TGTHOST,
|
||||
AIO_TGTPORT,
|
||||
AIO_TGTUSER,
|
||||
AIO_TGTPASS,
|
||||
|
||||
AIO_CLRNAME,
|
||||
AIO_ADDNAME,
|
||||
AIO_BYPNAME
|
||||
}
|
||||
|
||||
private static class Methods
|
||||
{
|
||||
[DllImport("Redirector.bin", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern bool aio_dial(NameList 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 void 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();
|
||||
}
|
||||
|
||||
public bool Create(Models.Server.Server s, Models.Mode.Mode m)
|
||||
{
|
||||
Global.Logger.Info(String.Format("{0:x} Redirector.bin", Utils.FileHelper.Checksum("bin\\Redirector.bin")));
|
||||
|
||||
var mode = m as Models.Mode.ProcessMode.ProcessMode;
|
||||
Methods.aio_dial(NameList.AIO_FILTERLOOPBACK, mode.Loopback ? "true" : "false");
|
||||
Methods.aio_dial(NameList.AIO_FILTERINTRANET, mode.Intranet ? "true" : "false");
|
||||
Methods.aio_dial(NameList.AIO_FILTERTCP, mode.TCP ? "true" : "false");
|
||||
Methods.aio_dial(NameList.AIO_FILTERUDP, mode.UDP ? "true" : "false");
|
||||
|
||||
Methods.aio_dial(NameList.AIO_CLRNAME, "");
|
||||
Methods.aio_dial(NameList.AIO_BYPNAME, AppDomain.CurrentDomain.BaseDirectory.Replace("\\", "\\\\"));
|
||||
for (int i = 0; i < mode.BypassList.Count; i++) if (!Methods.aio_dial(NameList.AIO_BYPNAME, mode.BypassList[i])) return false;
|
||||
for (int i = 0; i < mode.HandleList.Count; i++) if (!Methods.aio_dial(NameList.AIO_ADDNAME, mode.HandleList[i])) return false;
|
||||
|
||||
switch (s.Type)
|
||||
{
|
||||
case Models.Server.ServerType.Socks:
|
||||
{
|
||||
var node = s as Models.Server.Socks.Socks;
|
||||
Methods.aio_dial(NameList.AIO_TGTHOST, node.Resolve());
|
||||
Methods.aio_dial(NameList.AIO_TGTPORT, node.Port.ToString());
|
||||
|
||||
if (!String.IsNullOrEmpty(node.Username))
|
||||
{
|
||||
Methods.aio_dial(NameList.AIO_TGTUSER, node.Username);
|
||||
}
|
||||
|
||||
if (!String.IsNullOrEmpty(node.Password))
|
||||
{
|
||||
Methods.aio_dial(NameList.AIO_TGTPASS, node.Password);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
Methods.aio_dial(NameList.AIO_TGTHOST, "127.0.0.1");
|
||||
Methods.aio_dial(NameList.AIO_TGTPORT, Global.Config.Ports.Socks.ToString());
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return Methods.aio_init();
|
||||
}
|
||||
|
||||
public bool Delete()
|
||||
{
|
||||
Methods.aio_free();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,138 +0,0 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Netch.Controllers.Mode
|
||||
{
|
||||
public class RedirectorController : Interface.IController
|
||||
{
|
||||
private enum NameList : int
|
||||
{
|
||||
TYPE_FILTERLOOPBACK,
|
||||
TYPE_FILTERTCP,
|
||||
TYPE_FILTERUDP,
|
||||
TYPE_CLRNAME,
|
||||
TYPE_ADDNAME,
|
||||
TYPE_BYPNAME,
|
||||
TYPE_DNSHOST,
|
||||
TYPE_TCPLISN,
|
||||
TYPE_TCPTYPE,
|
||||
TYPE_TCPHOST,
|
||||
TYPE_TCPUSER,
|
||||
TYPE_TCPPASS,
|
||||
TYPE_TCPMETH,
|
||||
TYPE_TCPPROT,
|
||||
TYPE_TCPPRPA,
|
||||
TYPE_TCPOBFS,
|
||||
TYPE_TCPOBPA,
|
||||
TYPE_UDPLISN,
|
||||
TYPE_UDPTYPE,
|
||||
TYPE_UDPHOST,
|
||||
TYPE_UDPUSER,
|
||||
TYPE_UDPPASS,
|
||||
TYPE_UDPMETH,
|
||||
TYPE_UDPPROT,
|
||||
TYPE_UDPPRPA,
|
||||
TYPE_UDPOBFS,
|
||||
TYPE_UDPOBPA
|
||||
}
|
||||
|
||||
private static class Methods
|
||||
{
|
||||
[DllImport("Redirector.bin", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern bool aio_dial(NameList 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();
|
||||
}
|
||||
|
||||
public bool Create(Models.Server.Server s, Models.Mode.Mode m)
|
||||
{
|
||||
Global.Logger.Info(String.Format("{0:x} Redirector.bin", Utils.FileHelper.Checksum("bin\\Redirector.bin")));
|
||||
|
||||
var mode = m as Models.Mode.ProcessMode.ProcessMode;
|
||||
Methods.aio_dial(NameList.TYPE_FILTERLOOPBACK, mode.Loopback ? "true" : "false");
|
||||
Methods.aio_dial(NameList.TYPE_FILTERTCP, mode.TCP ? "true" : "false");
|
||||
Methods.aio_dial(NameList.TYPE_FILTERUDP, mode.UDP ? "true" : "false");
|
||||
|
||||
Methods.aio_dial(NameList.TYPE_CLRNAME, "");
|
||||
Methods.aio_dial(NameList.TYPE_BYPNAME, AppDomain.CurrentDomain.BaseDirectory.Replace("\\", "\\\\"));
|
||||
for (int i = 0; i < mode.HandleList.Count; i++) if (!Methods.aio_dial(NameList.TYPE_ADDNAME, mode.HandleList[i])) return false;
|
||||
for (int i = 0; i < mode.BypassList.Count; i++) if (!Methods.aio_dial(NameList.TYPE_BYPNAME, mode.BypassList[i])) return false;
|
||||
|
||||
Methods.aio_dial(NameList.TYPE_TCPLISN, Global.Config.Ports.Redir.ToString());
|
||||
Methods.aio_dial(NameList.TYPE_UDPLISN, Global.Config.Ports.Redir.ToString());
|
||||
|
||||
switch (s.Type)
|
||||
{
|
||||
case Models.Server.ServerType.Socks:
|
||||
{
|
||||
var node = s as Models.Server.Socks.Socks;
|
||||
Methods.aio_dial(NameList.TYPE_TCPTYPE, "Socks");
|
||||
Methods.aio_dial(NameList.TYPE_UDPTYPE, "Socks");
|
||||
Methods.aio_dial(NameList.TYPE_TCPHOST, $"{node.Resolve()}:{node.Port}");
|
||||
Methods.aio_dial(NameList.TYPE_UDPHOST, $"{node.Resolve()}:{node.Port}");
|
||||
|
||||
if (!String.IsNullOrEmpty(node.Username))
|
||||
{
|
||||
Methods.aio_dial(NameList.TYPE_TCPUSER, node.Username);
|
||||
Methods.aio_dial(NameList.TYPE_UDPUSER, node.Username);
|
||||
}
|
||||
|
||||
if (!String.IsNullOrEmpty(node.Password))
|
||||
{
|
||||
Methods.aio_dial(NameList.TYPE_TCPPASS, node.Password);
|
||||
Methods.aio_dial(NameList.TYPE_UDPPASS, node.Password);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case Models.Server.ServerType.Shadowsocks:
|
||||
{
|
||||
var node = s as Models.Server.Shadowsocks.Shadowsocks;
|
||||
if (String.IsNullOrEmpty(node.OBFS))
|
||||
{
|
||||
Methods.aio_dial(NameList.TYPE_TCPTYPE, "Shadowsocks");
|
||||
Methods.aio_dial(NameList.TYPE_UDPTYPE, "Shadowsocks");
|
||||
Methods.aio_dial(NameList.TYPE_TCPHOST, $"{node.Resolve()}:{node.Port}");
|
||||
Methods.aio_dial(NameList.TYPE_UDPHOST, $"{node.Resolve()}:{node.Port}");
|
||||
Methods.aio_dial(NameList.TYPE_TCPPASS, node.Passwd);
|
||||
Methods.aio_dial(NameList.TYPE_UDPPASS, node.Passwd);
|
||||
Methods.aio_dial(NameList.TYPE_TCPMETH, node.Method);
|
||||
Methods.aio_dial(NameList.TYPE_UDPMETH, node.Method);
|
||||
}
|
||||
else
|
||||
{
|
||||
Methods.aio_dial(NameList.TYPE_TCPTYPE, "Socks");
|
||||
Methods.aio_dial(NameList.TYPE_UDPTYPE, "Socks");
|
||||
Methods.aio_dial(NameList.TYPE_TCPHOST, $"127.0.0.1:{Global.Config.Ports.Socks}");
|
||||
Methods.aio_dial(NameList.TYPE_UDPHOST, $"127.0.0.1:{Global.Config.Ports.Socks}");
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
Methods.aio_dial(NameList.TYPE_TCPTYPE, "Socks");
|
||||
Methods.aio_dial(NameList.TYPE_UDPTYPE, "Socks");
|
||||
Methods.aio_dial(NameList.TYPE_TCPHOST, $"127.0.0.1:{Global.Config.Ports.Socks}");
|
||||
Methods.aio_dial(NameList.TYPE_UDPHOST, $"127.0.0.1:{Global.Config.Ports.Socks}");
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return Methods.aio_init();
|
||||
}
|
||||
|
||||
public bool Delete()
|
||||
{
|
||||
return Methods.aio_free();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,239 +0,0 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Management;
|
||||
using System.Net;
|
||||
using System.Net.NetworkInformation;
|
||||
using System.Net.Sockets;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Netch.Controllers.Mode
|
||||
{
|
||||
public class TapController : Interface.IController
|
||||
{
|
||||
private enum NameList : int
|
||||
{
|
||||
TYPE_BYPBIND,
|
||||
TYPE_BYPLIST,
|
||||
TYPE_DNSADDR,
|
||||
TYPE_ADAPMTU,
|
||||
TYPE_TCPREST,
|
||||
TYPE_TCPTYPE,
|
||||
TYPE_TCPHOST,
|
||||
TYPE_TCPUSER,
|
||||
TYPE_TCPPASS,
|
||||
TYPE_TCPMETH,
|
||||
TYPE_TCPPROT,
|
||||
TYPE_TCPPRPA,
|
||||
TYPE_TCPOBFS,
|
||||
TYPE_TCPOBPA,
|
||||
TYPE_UDPREST,
|
||||
TYPE_UDPTYPE,
|
||||
TYPE_UDPHOST,
|
||||
TYPE_UDPUSER,
|
||||
TYPE_UDPPASS,
|
||||
TYPE_UDPMETH,
|
||||
TYPE_UDPPROT,
|
||||
TYPE_UDPPRPA,
|
||||
TYPE_UDPOBFS,
|
||||
TYPE_UDPOBPA
|
||||
}
|
||||
|
||||
private static class Methods
|
||||
{
|
||||
[DllImport("tap2socks.bin", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern bool tap_dial(NameList name, string value);
|
||||
|
||||
[DllImport("tap2socks.bin", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern bool tap_init();
|
||||
|
||||
[DllImport("tap2socks.bin", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern bool tap_free();
|
||||
|
||||
[DllImport("tap2socks.bin", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern string tap_name();
|
||||
|
||||
[DllImport("tap2socks.bin", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern ulong tap_getUP();
|
||||
|
||||
[DllImport("tap2socks.bin", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern ulong tap_getDL();
|
||||
}
|
||||
|
||||
private Tools.TunTap.Outbound Outbound = new();
|
||||
private Interface.IController DNSController;
|
||||
|
||||
private bool AssignInterface()
|
||||
{
|
||||
var index = Utils.RouteHelper.GetInterfaceIndexByDescription(Methods.tap_name());
|
||||
|
||||
var address = Global.Config.TunMode.Network.Split('/')[0];
|
||||
var netmask = byte.Parse(Global.Config.TunMode.Network.Split('/')[1]);
|
||||
if (!Utils.RouteHelper.CreateUnicastIP(AddressFamily.InterNetwork, address, netmask, index))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
NetworkInterface adapter = Utils.RouteHelper.GetInterfaceByIndex(index);
|
||||
if (adapter == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
using (var wmi = new ManagementClass("Win32_NetworkAdapterConfiguration"))
|
||||
{
|
||||
using var ins = wmi.GetInstances();
|
||||
var ada = ins.Cast<ManagementObject>().First(m => m["Description"].ToString() == adapter.Description);
|
||||
|
||||
var dns = new[] { "127.0.0.1" };
|
||||
if (Global.Config.TunMode.DNS != "aiodns")
|
||||
{
|
||||
dns[0] = Global.Config.TunMode.DNS;
|
||||
}
|
||||
|
||||
using var ord = wmi.GetMethodParameters("SetDNSServerSearchOrder");
|
||||
ord["DNSServerSearchOrder"] = dns;
|
||||
|
||||
ada.InvokeMethod("SetDNSServerSearchOrder", ord, null);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool CreateServerRoute(Models.Server.Server s)
|
||||
{
|
||||
var addr = Utils.DNS.Fetch(s.Host);
|
||||
if (addr == IPAddress.Any)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (addr.AddressFamily == AddressFamily.InterNetworkV6)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return Utils.RouteHelper.CreateRoute(AddressFamily.InterNetwork, addr.ToString(), 32, this.Outbound.Gateway.ToString(), this.Outbound.Index);
|
||||
}
|
||||
|
||||
private bool CreateHandleRoute(Models.Mode.TunMode.TunMode mode)
|
||||
{
|
||||
var index = Utils.RouteHelper.GetInterfaceIndexByDescription(Methods.tap_name());
|
||||
|
||||
for (int i = 0; i < mode.HandleList.Count; i++)
|
||||
{
|
||||
var address = mode.HandleList[i].Split('/')[0];
|
||||
var netmask = byte.Parse(mode.HandleList[i].Split('/')[1]);
|
||||
|
||||
Utils.RouteHelper.CreateRoute(AddressFamily.InterNetwork, address, netmask, Global.Config.TunMode.Gateway, index);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Create(Models.Server.Server s, Models.Mode.Mode m)
|
||||
{
|
||||
Global.Logger.Info(String.Format("{0:x} tap2socks.bin", Utils.FileHelper.Checksum("bin\\tap2socks.bin")));
|
||||
|
||||
if (!this.Outbound.Get())
|
||||
{
|
||||
Global.Logger.Error(String.Format("Failed to fetch outbound"));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Methods.tap_dial(NameList.TYPE_BYPBIND, this.Outbound.Address.ToString());
|
||||
|
||||
var mode = m as Models.Mode.TunMode.TunMode;
|
||||
if (mode.BypassList.Count > 0)
|
||||
{
|
||||
if (File.Exists("ipcidr.txt"))
|
||||
{
|
||||
File.Delete("ipcidr.txt");
|
||||
}
|
||||
File.WriteAllLines("ipcidr.txt", mode.BypassList);
|
||||
|
||||
Methods.tap_dial(NameList.TYPE_BYPLIST, "ipcidr.txt");
|
||||
}
|
||||
else
|
||||
{
|
||||
Methods.tap_dial(NameList.TYPE_BYPLIST, "disabled");
|
||||
}
|
||||
|
||||
Methods.tap_dial(NameList.TYPE_DNSADDR, (Global.Config.TunMode.DNS == "aiodns") ? "127.0.0.1" : Global.Config.TunMode.DNS);
|
||||
Methods.tap_dial(NameList.TYPE_TCPREST, "");
|
||||
Methods.tap_dial(NameList.TYPE_UDPREST, "");
|
||||
|
||||
switch (s.Type)
|
||||
{
|
||||
case Models.Server.ServerType.Socks:
|
||||
{
|
||||
var node = s as Models.Server.Socks.Socks;
|
||||
|
||||
Methods.tap_dial(NameList.TYPE_TCPTYPE, "Socks");
|
||||
Methods.tap_dial(NameList.TYPE_UDPTYPE, "Socks");
|
||||
Methods.tap_dial(NameList.TYPE_TCPHOST, $"{node.Resolve()}:{node.Port}");
|
||||
Methods.tap_dial(NameList.TYPE_UDPHOST, $"{node.Resolve()}:{node.Port}");
|
||||
|
||||
if (!String.IsNullOrEmpty(node.Username))
|
||||
{
|
||||
Methods.tap_dial(NameList.TYPE_TCPUSER, node.Username);
|
||||
Methods.tap_dial(NameList.TYPE_UDPUSER, node.Username);
|
||||
}
|
||||
|
||||
if (!String.IsNullOrEmpty(node.Password))
|
||||
{
|
||||
Methods.tap_dial(NameList.TYPE_TCPPASS, node.Password);
|
||||
Methods.tap_dial(NameList.TYPE_UDPPASS, node.Password);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
Methods.tap_dial(NameList.TYPE_TCPTYPE, "Socks");
|
||||
Methods.tap_dial(NameList.TYPE_TCPHOST, $"127.0.0.1:{Global.Config.Ports.Socks}");
|
||||
Methods.tap_dial(NameList.TYPE_UDPTYPE, "Socks");
|
||||
Methods.tap_dial(NameList.TYPE_UDPHOST, $"127.0.0.1:{Global.Config.Ports.Socks}");
|
||||
break;
|
||||
}
|
||||
|
||||
if (!Methods.tap_init())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
this.DNSController = new Other.DNS.AioDNSController();
|
||||
if (!this.DNSController.Create(s, m))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!this.AssignInterface())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!this.CreateServerRoute(s))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!this.CreateHandleRoute(mode))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (File.Exists("ipcidr.txt"))
|
||||
{
|
||||
File.Delete("ipcidr.txt");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete()
|
||||
{
|
||||
this.DNSController?.Delete();
|
||||
|
||||
return Methods.tap_free();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -137,7 +137,7 @@ namespace Netch.Controllers.Mode
|
||||
|
||||
if (!this.Outbound.Get())
|
||||
{
|
||||
Global.Logger.Error(String.Format("Failed to fetch outbound"));
|
||||
Global.Logger.Error("Fetch outbound adapter failed");
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -201,7 +201,15 @@ namespace Netch.Controllers.Mode
|
||||
return false;
|
||||
}
|
||||
|
||||
this.DNSController = new Other.DNS.AioDNSController();
|
||||
if (Global.Config.Generic.AioDNS)
|
||||
{
|
||||
this.DNSController = new Other.DNS.AioDNSController();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.DNSController = new Other.DNS.DNSProxyController();
|
||||
}
|
||||
|
||||
if (!this.DNSController.Create(s, m))
|
||||
{
|
||||
return false;
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace Netch.Controllers.Mode
|
||||
{
|
||||
public class WinDivertController : Interface.IController
|
||||
{
|
||||
public bool Create(Models.Server.Server s, Models.Mode.Mode m)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public bool Delete()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
namespace Netch.Controllers.Mode
|
||||
{
|
||||
public class WmpController : Interface.IController
|
||||
{
|
||||
public bool Create(Models.Server.Server s, Models.Mode.Mode m)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public bool Delete()
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,43 +2,49 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Netch.Controllers.Other.DNS
|
||||
{
|
||||
public class AioDNSController : Interface.IController
|
||||
{
|
||||
private Tools.Guard Guard = new()
|
||||
private enum NameList : int
|
||||
{
|
||||
StartInfo = new ProcessStartInfo()
|
||||
{
|
||||
FileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "bin\\aiodns.exe"),
|
||||
WorkingDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "bin"),
|
||||
CreateNoWindow = true,
|
||||
UseShellExecute = false,
|
||||
WindowStyle = ProcessWindowStyle.Hidden
|
||||
},
|
||||
JudgmentStarted = new List<string>()
|
||||
{
|
||||
"Started"
|
||||
},
|
||||
JudgmentStopped = new List<string>()
|
||||
{
|
||||
"[aiodns][main]"
|
||||
},
|
||||
AutoRestart = true
|
||||
};
|
||||
TYPE_REST,
|
||||
TYPE_LIST,
|
||||
TYPE_LISN,
|
||||
TYPE_CDNS,
|
||||
TYPE_ODNS
|
||||
}
|
||||
|
||||
private static class Methods
|
||||
{
|
||||
[DllImport("aiodns.bin", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern bool aiodns_dial(NameList name, string value);
|
||||
|
||||
[DllImport("aiodns.bin", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern bool aiodns_init();
|
||||
|
||||
[DllImport("aiodns.bin", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void aiodns_free();
|
||||
}
|
||||
|
||||
public bool Create(Models.Server.Server s, Models.Mode.Mode m)
|
||||
{
|
||||
Global.Logger.Info(String.Format("{0:x} aiodns.exe", Utils.FileHelper.Checksum("bin\\aiodns.exe")));
|
||||
Global.Logger.Info(String.Format("{0:x} aiodns.bin", Utils.FileHelper.Checksum("bin\\aiodns.bin")));
|
||||
|
||||
this.Guard.StartInfo.Arguments = String.Format("-c {} -l {} -cdns {} -odns {}", ".\\aiodns.conf", ":53", Global.Config.AioDNS.ChinaDNS, Global.Config.AioDNS.OtherDNS);
|
||||
return this.Guard.Create();
|
||||
Methods.aiodns_dial(NameList.TYPE_REST, "");
|
||||
Methods.aiodns_dial(NameList.TYPE_LIST, "chnsite.txt");
|
||||
Methods.aiodns_dial(NameList.TYPE_LISN, Global.Config.AioDNS.ListenPort.ToString());
|
||||
Methods.aiodns_dial(NameList.TYPE_CDNS, Global.Config.AioDNS.ChinaDNS);
|
||||
Methods.aiodns_dial(NameList.TYPE_ODNS, Global.Config.AioDNS.OtherDNS);
|
||||
|
||||
return Methods.aiodns_init();
|
||||
}
|
||||
|
||||
public bool Delete()
|
||||
{
|
||||
this.Guard.Delete();
|
||||
Methods.aiodns_free();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
|
||||
namespace Netch.Controllers.Other.DNS
|
||||
{
|
||||
public class CoreDNSController : Interface.IController
|
||||
{
|
||||
private Tools.Guard Guard = new()
|
||||
{
|
||||
StartInfo = new ProcessStartInfo()
|
||||
{
|
||||
FileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "bin\\CoreDNS.exe"),
|
||||
WorkingDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "bin"),
|
||||
CreateNoWindow = true,
|
||||
UseShellExecute = false,
|
||||
WindowStyle = ProcessWindowStyle.Hidden
|
||||
},
|
||||
JudgmentStarted = new List<string>()
|
||||
{
|
||||
},
|
||||
JudgmentStopped = new List<string>()
|
||||
{
|
||||
},
|
||||
AutoRestart = true
|
||||
};
|
||||
|
||||
public bool Create(Models.Server.Server s, Models.Mode.Mode m)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public bool Delete()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ using System.IO;
|
||||
|
||||
namespace Netch.Controllers.Other.DNS
|
||||
{
|
||||
public class DNSController : Interface.IController
|
||||
public class DNSProxyController : Interface.IController
|
||||
{
|
||||
private Tools.Guard Guard = new()
|
||||
{
|
||||
@@ -1,39 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
|
||||
namespace Netch.Controllers.Other.DNS
|
||||
{
|
||||
public class UnboundController : Interface.IController
|
||||
{
|
||||
private Tools.Guard Guard = new()
|
||||
{
|
||||
StartInfo = new ProcessStartInfo()
|
||||
{
|
||||
FileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "bin\\Unbound.exe"),
|
||||
WorkingDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "bin"),
|
||||
CreateNoWindow = true,
|
||||
UseShellExecute = false,
|
||||
WindowStyle = ProcessWindowStyle.Hidden
|
||||
},
|
||||
JudgmentStarted = new List<string>()
|
||||
{
|
||||
},
|
||||
JudgmentStopped = new List<string>()
|
||||
{
|
||||
},
|
||||
AutoRestart = true
|
||||
};
|
||||
|
||||
public bool Create(Models.Server.Server s, Models.Mode.Mode m)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public bool Delete()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace Netch.Controllers.Other.Web
|
||||
{
|
||||
public class PrivoxyController : Interface.IController
|
||||
{
|
||||
public bool Create(Models.Server.Server s, Models.Mode.Mode m)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public bool Delete()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace Netch.Controllers.Server
|
||||
{
|
||||
public class ClashController : Interface.IController
|
||||
{
|
||||
public bool Create(Models.Server.Server s, Models.Mode.Mode m)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public bool Delete()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Netch.Controllers.Server
|
||||
{
|
||||
public class HTTPController : Interface.IController
|
||||
public class WireGuardController : Interface.IController
|
||||
{
|
||||
public bool Create(Models.Server.Server s, Models.Mode.Mode m)
|
||||
{
|
||||
@@ -2,14 +2,22 @@
|
||||
{
|
||||
public class AioDNS
|
||||
{
|
||||
/// <summary>
|
||||
/// 监听地址
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("listenport")]
|
||||
public ushort ListenPort = 53;
|
||||
|
||||
/// <summary>
|
||||
/// 国内 DNS 地址
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("chinadns")]
|
||||
public string ChinaDNS = "tcp://119.29.29.29:53";
|
||||
|
||||
/// <summary>
|
||||
/// 国外 DNS 地址
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("otherdns")]
|
||||
public string OtherDNS = "tls://1.1.1.1:853";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,12 +34,6 @@ namespace Netch.Models.Config
|
||||
[Newtonsoft.Json.JsonProperty("sharemode")]
|
||||
public ShareMode ShareMode = new();
|
||||
|
||||
/// <summary>
|
||||
/// TapMode 配置
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("tapmode")]
|
||||
public TapMode TapMode = new();
|
||||
|
||||
/// <summary>
|
||||
/// TunMode 配置
|
||||
/// </summary>
|
||||
@@ -52,12 +46,24 @@ namespace Netch.Models.Config
|
||||
[Newtonsoft.Json.JsonProperty("aiodns")]
|
||||
public AioDNS AioDNS = new();
|
||||
|
||||
/// <summary>
|
||||
/// DNSProxy 配置
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("dnsproxy")]
|
||||
public DNSProxy DNSProxy = new();
|
||||
|
||||
/// <summary>
|
||||
/// V2Ray 配置
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("v2ray")]
|
||||
public V2Ray V2Ray = new();
|
||||
|
||||
/// <summary>
|
||||
/// V2Ray 配置
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("xray")]
|
||||
public XRay XRay = new();
|
||||
|
||||
/// <summary>
|
||||
/// STUN 配置
|
||||
/// </summary>
|
||||
|
||||
17
Netch/Models/Config/DNSProxy.cs
Normal file
17
Netch/Models/Config/DNSProxy.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Netch.Models.Config
|
||||
{
|
||||
public class DNSProxy
|
||||
{
|
||||
[Newtonsoft.Json.JsonProperty("otherdns")]
|
||||
public string OtherDNS = "tls://8.8.8.8:853";
|
||||
|
||||
[Newtonsoft.Json.JsonProperty("args")]
|
||||
public string Args = "";
|
||||
}
|
||||
}
|
||||
@@ -5,11 +5,25 @@
|
||||
/// <summary>
|
||||
/// 检查 Unstable 更新
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("unstable")]
|
||||
public bool Unstable = false;
|
||||
|
||||
/// <summary>
|
||||
/// 使用 ICMP 测试延迟
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("icmping")]
|
||||
public bool ICMPing = true;
|
||||
|
||||
/// <summary>
|
||||
/// 使用 AioDNS 解析器
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("aiodns")]
|
||||
public bool AioDNS = false;
|
||||
|
||||
/// <summary>
|
||||
/// 使用 XRay 后端
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("xray")]
|
||||
public bool XRay = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,11 +13,5 @@
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("mixed")]
|
||||
public int Mixed = 2082;
|
||||
|
||||
/// <summary>
|
||||
/// Redir 端口
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("redir")]
|
||||
public int Redir = 2083;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Netch.Models.Config
|
||||
{
|
||||
public class TapMode
|
||||
{
|
||||
/// <summary>
|
||||
/// 地址
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("network")]
|
||||
public string Network = "100.64.0.100/24";
|
||||
|
||||
/// <summary>
|
||||
/// 网关
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("gateway")]
|
||||
public string Gateway = "100.64.0.1";
|
||||
|
||||
/// <summary>
|
||||
/// DNS
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("dns")]
|
||||
public string DNS = "aiodns";
|
||||
|
||||
/// <summary>
|
||||
/// 绕过 IP 地址
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("bypass")]
|
||||
public List<string> BypassIPs = new();
|
||||
}
|
||||
}
|
||||
@@ -2,11 +2,6 @@
|
||||
{
|
||||
public class V2Ray
|
||||
{
|
||||
/// <summary>
|
||||
/// FullCone 支持(需要 xray-core 服务端版本 v1.3.0+)
|
||||
/// </summary>
|
||||
public bool FullCone = false;
|
||||
|
||||
/// <summary>
|
||||
/// 跳过证书认证
|
||||
/// </summary>
|
||||
|
||||
16
Netch/Models/Config/XRay.cs
Normal file
16
Netch/Models/Config/XRay.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Netch.Models.Config
|
||||
{
|
||||
public class XRay
|
||||
{
|
||||
/// <summary>
|
||||
/// FullCone 支持(需要 xray-core 服务端版本 v1.3.0+)
|
||||
/// </summary>
|
||||
public bool FullCone = false;
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
namespace Netch.Models.GitHub
|
||||
{
|
||||
public class Asset
|
||||
{
|
||||
/// <summary>
|
||||
/// name
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("name")]
|
||||
public string Name;
|
||||
|
||||
/// <summary>
|
||||
/// browser_download_url
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("browser_download_url")]
|
||||
public string URL;
|
||||
|
||||
/// <summary>
|
||||
/// size
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("size")]
|
||||
public ulong Size;
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Netch.Models.GitHub
|
||||
{
|
||||
/// <summary>
|
||||
/// https://api.github.com/repos/{owner}/{repo}/releases
|
||||
/// </summary>
|
||||
public class Release
|
||||
{
|
||||
/// <summary>
|
||||
/// id
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("id")]
|
||||
public int ID;
|
||||
|
||||
/// <summary>
|
||||
/// html_url
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("html_url")]
|
||||
public string URL;
|
||||
|
||||
/// <summary>
|
||||
/// tag_name
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("tag_name")]
|
||||
public string VerCode;
|
||||
|
||||
/// <summary>
|
||||
/// draft
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("draft")]
|
||||
public bool Draft;
|
||||
|
||||
/// <summary>
|
||||
/// prerelease
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("prerelease")]
|
||||
public bool Unstable;
|
||||
|
||||
/// <summary>
|
||||
/// assets
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("assets")]
|
||||
public List<Asset> Files;
|
||||
}
|
||||
}
|
||||
@@ -12,11 +12,6 @@
|
||||
/// </summary>
|
||||
ShareMode,
|
||||
|
||||
/// <summary>
|
||||
/// 网卡代理
|
||||
/// </summary>
|
||||
TapMode,
|
||||
|
||||
/// <summary>
|
||||
/// 网卡代理
|
||||
/// </summary>
|
||||
@@ -26,10 +21,5 @@
|
||||
/// 网页代理
|
||||
/// </summary>
|
||||
WebMode,
|
||||
|
||||
/// <summary>
|
||||
/// 代理转发
|
||||
/// </summary>
|
||||
WmpMode
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,12 @@ namespace Netch.Models.Mode.ProcessMode
|
||||
[Newtonsoft.Json.JsonProperty("filterLoopback")]
|
||||
public bool Loopback = false;
|
||||
|
||||
/// <summary>
|
||||
/// 过滤 内网 流量
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("filterIntranet")]
|
||||
public bool Intranet = false;
|
||||
|
||||
/// <summary>
|
||||
/// 过滤 ICMP 流量(伪造 ICMP 回复)
|
||||
/// </summary>
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Netch.Models.Mode.TapMode
|
||||
{
|
||||
public class TapMode : Mode
|
||||
{
|
||||
public TapMode()
|
||||
{
|
||||
this.Type = ModeType.TapMode;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 绕过列表(IP CIDR)
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("bypass")]
|
||||
public List<string> BypassList;
|
||||
|
||||
/// <summary>
|
||||
/// 代理列表(IP CIDR)
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("handle")]
|
||||
public List<string> HandleList;
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
namespace Netch.Models.Mode.WmpMode
|
||||
{
|
||||
public class WmpMode : Mode
|
||||
{
|
||||
public WmpMode()
|
||||
{
|
||||
this.Type = ModeType.WmpMode;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 监听地址(为空则监听所有 IPv4 + IPv6 地址)
|
||||
/// </summary>
|
||||
public string ListenAddr;
|
||||
|
||||
/// <summary>
|
||||
/// 监听端口
|
||||
/// </summary>
|
||||
public ushort ListenPort;
|
||||
|
||||
/// <summary>
|
||||
/// 远端地址
|
||||
/// </summary>
|
||||
public string RemoteAddr;
|
||||
|
||||
/// <summary>
|
||||
/// 远端端口
|
||||
/// </summary>
|
||||
public ushort RemotePort;
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
namespace Netch.Models.Server.Clash
|
||||
{
|
||||
public class Clash : Server
|
||||
{
|
||||
public Clash()
|
||||
{
|
||||
this.Type = ServerType.Clash;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 自定义配置
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("custom")]
|
||||
public bool Custom = true;
|
||||
|
||||
/// <summary>
|
||||
/// 自定义配置文件路径
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("filepath")]
|
||||
public string FilePath;
|
||||
|
||||
/// <summary>
|
||||
/// 解析链接
|
||||
/// </summary>
|
||||
/// <param name="link">链接</param>
|
||||
/// <returns>是否成功</returns>
|
||||
public bool ParseLink(string link)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -58,9 +58,10 @@ namespace Netch.Models.Server
|
||||
ServerType.Socks => "S5",
|
||||
ServerType.Shadowsocks => "SS",
|
||||
ServerType.ShadowsocksR => "SR",
|
||||
ServerType.WireGuard => "WG",
|
||||
ServerType.Trojan => "TR",
|
||||
ServerType.VLess => "VL",
|
||||
ServerType.VMess => "VM",
|
||||
ServerType.VLess => "VL",
|
||||
_ => "UN",
|
||||
};
|
||||
|
||||
|
||||
@@ -2,16 +2,6 @@
|
||||
{
|
||||
public enum ServerType : int
|
||||
{
|
||||
/// <summary>
|
||||
/// HTTP
|
||||
/// </summary>
|
||||
HTTP,
|
||||
|
||||
/// <summary>
|
||||
/// Clash
|
||||
/// </summary>
|
||||
Clash,
|
||||
|
||||
/// <summary>
|
||||
/// Socks5
|
||||
/// </summary>
|
||||
@@ -27,19 +17,24 @@
|
||||
/// </summary>
|
||||
ShadowsocksR,
|
||||
|
||||
/// <summary>
|
||||
/// WireGuard
|
||||
/// </summary>
|
||||
WireGuard,
|
||||
|
||||
/// <summary>
|
||||
/// Trojan
|
||||
/// </summary>
|
||||
Trojan,
|
||||
|
||||
/// <summary>
|
||||
/// VLess
|
||||
/// </summary>
|
||||
VLess,
|
||||
|
||||
/// <summary>
|
||||
/// VMess
|
||||
/// </summary>
|
||||
VMess
|
||||
VMess,
|
||||
|
||||
/// <summary>
|
||||
/// VLess
|
||||
/// </summary>
|
||||
VLess
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace Netch.Utils
|
||||
/// <summary>
|
||||
/// 缓存表
|
||||
/// </summary>
|
||||
private static readonly Hashtable Cache = new Hashtable();
|
||||
private static Hashtable Cache = new Hashtable();
|
||||
|
||||
/// <summary>
|
||||
/// 获取 IP 地址
|
||||
|
||||
@@ -1,73 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Netch.Utils
|
||||
{
|
||||
public static class GitHub
|
||||
{
|
||||
/// <summary>
|
||||
/// 地址
|
||||
/// </summary>
|
||||
public static readonly string URL = "https://api.github.com/repos/NetchX/Netch/releases";
|
||||
|
||||
/// <summary>
|
||||
/// 检查是否有更新
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static int HasUpdate()
|
||||
{
|
||||
var list = GetReleaseList();
|
||||
if (list.Count < 1)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (int i = 0; i < list.Count; i++)
|
||||
{
|
||||
if (list[i].Draft)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (Global.Config.Generic.Unstable)
|
||||
{
|
||||
if (list[i].Unstable)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (list[i].VerCode.Equals(Global.VerCode))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return list[i].ID;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取单个发布
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public static Models.GitHub.Release GetRelease(int id)
|
||||
{
|
||||
var data = HTTP.GetString($"{URL}/{id}");
|
||||
|
||||
return Newtonsoft.Json.JsonConvert.DeserializeObject<Models.GitHub.Release>(data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取发布列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static List<Models.GitHub.Release> GetReleaseList()
|
||||
{
|
||||
var data = HTTP.GetString(URL);
|
||||
|
||||
return Newtonsoft.Json.JsonConvert.DeserializeObject<List<Models.GitHub.Release>>(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@ namespace Netch.Utils
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[DllImport("RouteHelper.bin", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern ulong ConvertLuidToIndex(ulong id);
|
||||
public static extern uint ConvertLuidToIndex(ulong id);
|
||||
|
||||
/// <summary>
|
||||
/// 绑定 IP 地址(Windows XP)
|
||||
@@ -24,7 +24,7 @@ namespace Netch.Utils
|
||||
/// <param name="index"></param>
|
||||
/// <returns></returns>
|
||||
[DllImport("RouteHelper.bin", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern bool CreateIPv4(string address, string netmask, ulong index);
|
||||
public static extern bool CreateIPv4(string address, string netmask, uint index);
|
||||
|
||||
/// <summary>
|
||||
/// 绑定 IP 地址
|
||||
@@ -35,7 +35,7 @@ namespace Netch.Utils
|
||||
/// <param name="index"></param>
|
||||
/// <returns></returns>
|
||||
[DllImport("RouteHelper.bin", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern bool CreateUnicastIP(AddressFamily inet, string address, byte cidr, ulong index);
|
||||
public static extern bool CreateUnicastIP(AddressFamily inet, string address, byte cidr, uint index);
|
||||
|
||||
/// <summary>
|
||||
/// 创建路由
|
||||
@@ -47,7 +47,7 @@ namespace Netch.Utils
|
||||
/// <param name="index"></param>
|
||||
/// <returns></returns>
|
||||
[DllImport("RouteHelper.bin", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern bool CreateRoute(AddressFamily inet, string address, byte cidr, string gateway, ulong index);
|
||||
public static extern bool CreateRoute(AddressFamily inet, string address, byte cidr, string gateway, uint index, uint metric = 1);
|
||||
|
||||
/// <summary>
|
||||
/// 删除路由
|
||||
@@ -59,7 +59,7 @@ namespace Netch.Utils
|
||||
/// <param name="index"></param>
|
||||
/// <returns></returns>
|
||||
[DllImport("RouteHelper.bin", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern bool DeleteRoute(AddressFamily inet, string address, byte cidr, string gateway, ulong index);
|
||||
public static extern bool DeleteRoute(AddressFamily inet, string address, byte cidr, string gateway, uint index);
|
||||
|
||||
/// <summary>
|
||||
/// 使用索引获取适配器
|
||||
|
||||
Reference in New Issue
Block a user