replace eycorsican/go-tun2socks with aiocloud/tun2socks(WinTUN)

This commit is contained in:
ChsBuffer
2021-03-26 17:50:57 +08:00
parent f8148cb730
commit a080de6ca4
17 changed files with 262 additions and 310 deletions

View File

@@ -3,13 +3,14 @@ using System.Net.NetworkInformation;
namespace Netch.Models
{
public interface IAdapter
public interface IAdapter
{
public abstract int Index { get; }
string AdapterId { get; }
public abstract IPAddress Gateway { get; }
int InterfaceIndex { get; }
public abstract NetworkInterface NetworkInterface { get; }
IPAddress Gateway { get; }
NetworkInterface NetworkInterface { get; }
}
}

View File

@@ -23,7 +23,7 @@ namespace Netch.Models
.First(ni => ni.Supports(NetworkInterfaceComponent.IPv4) &&
ni.GetIPProperties().GetIPv4Properties().Index == pRoute.dwForwardIfIndex);
Index = (int) pRoute.dwForwardIfIndex;
InterfaceIndex = (int) pRoute.dwForwardIfIndex;
Gateway = new IPAddress(pRoute.dwForwardNextHop.S_un_b);
_parametersRegistry =
Registry.LocalMachine.OpenSubKey($@"SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\{NetworkInterface.Id}", true)!;
@@ -31,14 +31,16 @@ namespace Netch.Models
if (logging)
{
Logging.Info($"出口 网关 地址:{Gateway}");
Logging.Info($"出口适配器:{NetworkInterface.Name} {NetworkInterface.Id} {NetworkInterface.Description}, index: {Index}");
Logging.Info($"出口适配器:{NetworkInterface.Name} {NetworkInterface.Id} {NetworkInterface.Description}, index: {InterfaceIndex}");
}
}
public string AdapterId => throw new NotImplementedException();
/// <summary>
/// 索引
/// </summary>
public int Index { get; }
public int InterfaceIndex { get; }
/// <summary>
/// 网关
@@ -47,7 +49,6 @@ namespace Netch.Models
public NetworkInterface NetworkInterface { get; }
public string DNS
{
get

View File

@@ -6,7 +6,7 @@ namespace Netch.Models
/// <summary>
/// TUN/TAP 适配器配置类
/// </summary>
public class TUNTAPConfig
public class TUNConfig
{
/// <summary>
/// 地址
@@ -37,11 +37,6 @@ namespace Netch.Models
/// 使用自定义 DNS 设置
/// </summary>
public bool UseCustomDNS { get; set; } = false;
/// <summary>
/// 使用Fake DNS
/// </summary>
public bool UseFakeDNS { get; set; } = false;
}
public class KcpConfig
@@ -280,7 +275,7 @@ namespace Netch.Models
/// <summary>
/// TUNTAP 适配器配置
/// </summary>
public TUNTAPConfig TUNTAP { get; set; } = new();
public TUNConfig WinTUN { get; set; } = new();
/// <summary>
/// 是否打开软件时更新订阅

View File

@@ -1,30 +0,0 @@
using System.Linq;
using System.Net;
using System.Net.NetworkInformation;
using Netch.Controllers;
using Netch.Utils;
namespace Netch.Models
{
public class TapAdapter : IAdapter
{
public TapAdapter()
{
Index = -1;
ComponentID = TUNTAP.GetComponentID() ?? throw new MessageException("TAP 适配器未安装");
// 根据 ComponentID 寻找 Tap适配器
NetworkInterface = NetworkInterface.GetAllNetworkInterfaces().First(i => i.Id == ComponentID);
Index = NetworkInterface.GetIPProperties().GetIPv4Properties().Index;
Logging.Info($"TAP 适配器:{NetworkInterface.Name} {NetworkInterface.Id} {NetworkInterface.Description}, index: {Index}");
}
public string ComponentID { get; }
public int Index { get; }
public IPAddress Gateway => IPAddress.Parse(Global.Settings.TUNTAP.Gateway);
public NetworkInterface NetworkInterface { get; }
}
}

View File

@@ -0,0 +1,30 @@
using System;
using System.Linq;
using System.Net;
using System.Net.NetworkInformation;
using Netch.Utils;
namespace Netch.Models
{
public class TunAdapter : IAdapter
{
private const string ComponentIdWintun = "wintun";
public TunAdapter()
{
AdapterId = AdapterUtils.GetAdapterId(ComponentIdWintun) ?? throw new Exception("wintun adapter not found");
NetworkInterface = NetworkInterface.GetAllNetworkInterfaces().First(i => i.Id == AdapterId);
InterfaceIndex = NetworkInterface.GetIPProperties().GetIPv4Properties().Index;
Logging.Info($"TAP 适配器:{NetworkInterface.Name} {NetworkInterface.Id} {NetworkInterface.Description}, index: {InterfaceIndex}");
}
public string AdapterId { get; set; }
public int InterfaceIndex { get; }
public IPAddress Gateway { get; } = IPAddress.Parse("100.64.0.1");
public NetworkInterface NetworkInterface { get; }
}
}