From bedafc23d4caf5e9a88129b0dcbbe1dadb361558 Mon Sep 17 00:00:00 2001 From: Hellojack <106379370+H1JK@users.noreply.github.com> Date: Fri, 10 Jun 2022 11:00:57 +0800 Subject: [PATCH] SOCKS : Support version 4 & 4a --- Netch/Resources/zh-CN | 1 + Netch/Servers/Socks5/Socks5Form.cs | 5 +++++ Netch/Servers/Socks5/Socks5Server.cs | 17 ++++++++++++++++- Netch/Servers/Socks5/Socks5Util.cs | 6 +++--- Netch/Servers/V2ray/V2rayConfig.cs | 2 ++ Netch/Servers/V2ray/V2rayConfigUtils.cs | 9 +++++---- 6 files changed, 32 insertions(+), 8 deletions(-) diff --git a/Netch/Resources/zh-CN b/Netch/Resources/zh-CN index d9a968ef..f91760ab 100644 --- a/Netch/Resources/zh-CN +++ b/Netch/Resources/zh-CN @@ -48,6 +48,7 @@ "Address": "地址", "Username": "用户名", "Password": "密码", + "Version": "版本", "User ID": "用户 ID", "Alter ID": "额外 ID", "Transfer Protocol": "传输协议", diff --git a/Netch/Servers/Socks5/Socks5Form.cs b/Netch/Servers/Socks5/Socks5Form.cs index 5b46d4b8..c0a16672 100644 --- a/Netch/Servers/Socks5/Socks5Form.cs +++ b/Netch/Servers/Socks5/Socks5Form.cs @@ -12,6 +12,11 @@ public class Socks5Form : ServerForm Server = server; CreateTextBox("Username", "Username", s => true, s => server.Username = s, server.Username.ValueOrDefault()); CreateTextBox("Password", "Password", s => true, s => server.Password = s, server.Password.ValueOrDefault()); + CreateComboBox("Version", + "Version", + SOCKSGlobal.Versions, + s => server.Version = s, + server.Version); (_remoteHostnameLabel, _remoteHostnameTextBox) = CreateTextBox("RemoteHostname", "Remote Address", s => true, diff --git a/Netch/Servers/Socks5/Socks5Server.cs b/Netch/Servers/Socks5/Socks5Server.cs index a6b50727..a83e4c69 100644 --- a/Netch/Servers/Socks5/Socks5Server.cs +++ b/Netch/Servers/Socks5/Socks5Server.cs @@ -4,7 +4,7 @@ namespace Netch.Servers; public class Socks5Server : Server { - public override string Type { get; } = "Socks5"; + public override string Type { get; } = "SOCKS"; /// /// 密码 @@ -18,6 +18,11 @@ public class Socks5Server : Server public string? RemoteHostname { get; set; } + /// + /// 版本 + /// + public string Version { get; set; } = SOCKSGlobal.Versions[0]; + public override string MaskedData() { return $"Auth: {Auth()}"; @@ -48,4 +53,14 @@ public class Socks5Server : Server { return !string.IsNullOrWhiteSpace(Username) && !string.IsNullOrWhiteSpace(Password); } +} + +public class SOCKSGlobal +{ + public static readonly List Versions = new() + { + "5", + "4a", + "4" + }; } \ No newline at end of file diff --git a/Netch/Servers/Socks5/Socks5Util.cs b/Netch/Servers/Socks5/Socks5Util.cs index 5675faf9..41c19266 100644 --- a/Netch/Servers/Socks5/Socks5Util.cs +++ b/Netch/Servers/Socks5/Socks5Util.cs @@ -7,11 +7,11 @@ public class Socks5Util : IServerUtil { public ushort Priority { get; } = 0; - public string TypeName { get; } = "Socks5"; + public string TypeName { get; } = "SOCKS"; - public string FullName { get; } = "Socks5"; + public string FullName { get; } = "SOCKS"; - public string ShortName { get; } = "S5"; + public string ShortName { get; } = "SOCKS"; public string[] UriScheme { get; } = { }; diff --git a/Netch/Servers/V2ray/V2rayConfig.cs b/Netch/Servers/V2ray/V2rayConfig.cs index 7a84228c..d864b759 100644 --- a/Netch/Servers/V2ray/V2rayConfig.cs +++ b/Netch/Servers/V2ray/V2rayConfig.cs @@ -40,6 +40,8 @@ public class OutboundConfiguration public object[] servers { get; set; } + public string version { get; set; } + public string address { get; set; } public ushort port { get; set; } diff --git a/Netch/Servers/V2ray/V2rayConfigUtils.cs b/Netch/Servers/V2ray/V2rayConfigUtils.cs index 5f98c7f2..bed4fe7a 100644 --- a/Netch/Servers/V2ray/V2rayConfigUtils.cs +++ b/Netch/Servers/V2ray/V2rayConfigUtils.cs @@ -42,7 +42,7 @@ public static class V2rayConfigUtils switch (server) { - case Socks5Server socks5: + case Socks5Server socks: { outbound.protocol = "socks"; outbound.settings.servers = new object[] @@ -51,19 +51,20 @@ public static class V2rayConfigUtils { address = await server.AutoResolveHostnameAsync(), port = server.Port, - users = socks5.Auth() + users = socks.Auth() ? new[] { new { - user = socks5.Username, - pass = socks5.Password, + user = socks.Username, + pass = socks.Password, level = 1 } } : null } }; + outbound.settings.version = socks.Version; outbound.mux.enabled = false; outbound.mux.concurrency = -1;