mirror of
https://github.com/netchx/netch.git
synced 2026-04-29 21:59:34 +08:00
done
This commit is contained in:
21
Netch/Models/GitHubRelease/Asset.cs
Normal file
21
Netch/Models/GitHubRelease/Asset.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
|
||||
namespace Netch.Models.GitHubRelease
|
||||
{
|
||||
public class Asset
|
||||
{
|
||||
public string url { get; set; }
|
||||
public int id { get; set; }
|
||||
public string node_id { get; set; }
|
||||
public string name { get; set; }
|
||||
public object label { get; set; }
|
||||
public GitHubUser uploader { get; set; }
|
||||
public string content_type { get; set; }
|
||||
public string state { get; set; }
|
||||
public int size { get; set; }
|
||||
public int download_count { get; set; }
|
||||
public DateTime created_at { get; set; }
|
||||
public DateTime updated_at { get; set; }
|
||||
public string browser_download_url { get; set; }
|
||||
}
|
||||
}
|
||||
16
Netch/Models/GitHubRelease/GitHubRelease.cs
Normal file
16
Netch/Models/GitHubRelease/GitHubRelease.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
namespace Netch.Models.GitHubRelease
|
||||
{
|
||||
public class GitHubRelease
|
||||
{
|
||||
private readonly string _owner;
|
||||
private readonly string _repo;
|
||||
|
||||
public string AllReleaseUrl => $@"https://api.github.com/repos/{_owner}/{_repo}/releases";
|
||||
|
||||
public GitHubRelease(string owner, string repo)
|
||||
{
|
||||
_owner = owner;
|
||||
_repo = repo;
|
||||
}
|
||||
}
|
||||
}
|
||||
24
Netch/Models/GitHubRelease/GitHubUser.cs
Normal file
24
Netch/Models/GitHubRelease/GitHubUser.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
namespace Netch.Models.GitHubRelease
|
||||
{
|
||||
public class GitHubUser
|
||||
{
|
||||
public string login { get; set; }
|
||||
public int id { get; set; }
|
||||
public string node_id { get; set; }
|
||||
public string avatar_url { get; set; }
|
||||
public string gravatar_id { get; set; }
|
||||
public string url { get; set; }
|
||||
public string html_url { get; set; }
|
||||
public string followers_url { get; set; }
|
||||
public string following_url { get; set; }
|
||||
public string gists_url { get; set; }
|
||||
public string starred_url { get; set; }
|
||||
public string subscriptions_url { get; set; }
|
||||
public string organizations_url { get; set; }
|
||||
public string repos_url { get; set; }
|
||||
public string events_url { get; set; }
|
||||
public string received_events_url { get; set; }
|
||||
public string type { get; set; }
|
||||
public bool site_admin { get; set; }
|
||||
}
|
||||
}
|
||||
26
Netch/Models/GitHubRelease/Release.cs
Normal file
26
Netch/Models/GitHubRelease/Release.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
|
||||
namespace Netch.Models.GitHubRelease
|
||||
{
|
||||
public class Release
|
||||
{
|
||||
public string url { get; set; }
|
||||
public string assets_url { get; set; }
|
||||
public string upload_url { get; set; }
|
||||
public string html_url { get; set; }
|
||||
public int id { get; set; }
|
||||
public string node_id { get; set; }
|
||||
public string tag_name { get; set; }
|
||||
public string target_commitish { get; set; }
|
||||
public string name { get; set; }
|
||||
public bool draft { get; set; }
|
||||
public GitHubUser author { get; set; }
|
||||
public bool prerelease { get; set; }
|
||||
public DateTime created_at { get; set; }
|
||||
public DateTime published_at { get; set; }
|
||||
public Asset[] assets { get; set; }
|
||||
public string tarball_url { get; set; }
|
||||
public string zipball_url { get; set; }
|
||||
public string body { get; set; }
|
||||
}
|
||||
}
|
||||
12
Netch/Models/GitHubRelease/VersionComparer.cs
Normal file
12
Netch/Models/GitHubRelease/VersionComparer.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Netch.Models.GitHubRelease
|
||||
{
|
||||
public class VersionComparer : IComparer<object>
|
||||
{
|
||||
public int Compare(object x, object y)
|
||||
{
|
||||
return VersionUtil.CompareVersion(x?.ToString(), y?.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
36
Netch/Models/GitHubRelease/VersionUtil.cs
Normal file
36
Netch/Models/GitHubRelease/VersionUtil.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Netch.Models.GitHubRelease
|
||||
{
|
||||
public static class VersionUtil
|
||||
{
|
||||
public static Release GetLatestRelease(IEnumerable<Release> releases, bool isPreRelease)
|
||||
{
|
||||
if (!isPreRelease)
|
||||
{
|
||||
releases = releases.Where(release => !release.prerelease);
|
||||
}
|
||||
releases = releases.Where(release => IsVersionString(release.tag_name));
|
||||
var ordered = releases.OrderByDescending(release => release.tag_name, new VersionComparer());
|
||||
return ordered.ElementAt(0);
|
||||
}
|
||||
|
||||
private static bool IsVersionString(string str)
|
||||
{
|
||||
return Version.TryParse(str, out _);
|
||||
}
|
||||
|
||||
/// <returns> =0:versions are equal</returns>
|
||||
/// <returns> >0:version1 is greater</returns>
|
||||
/// <returns> <0:version2 is greater</returns>
|
||||
public static int CompareVersion(string v1, string v2)
|
||||
{
|
||||
var version1 = new Version(v1);
|
||||
var version2 = new Version(v2);
|
||||
var res = version1.CompareTo(version2);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
}
|
||||
204
Netch/Models/Information/VMess.cs
Normal file
204
Netch/Models/Information/VMess.cs
Normal file
@@ -0,0 +1,204 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Netch.Models.Information
|
||||
{
|
||||
public class VMess
|
||||
{
|
||||
public class InboundSettings
|
||||
{
|
||||
public bool udp = true;
|
||||
}
|
||||
|
||||
public class Inbounds
|
||||
{
|
||||
public string listen = "127.0.0.1";
|
||||
|
||||
public int port = 2801;
|
||||
|
||||
public string protocol = "socks";
|
||||
|
||||
public InboundSettings settings;
|
||||
}
|
||||
|
||||
public class User
|
||||
{
|
||||
public string id;
|
||||
|
||||
public int alterId;
|
||||
|
||||
public string security;
|
||||
}
|
||||
|
||||
public class VNext
|
||||
{
|
||||
public string address;
|
||||
|
||||
public int port;
|
||||
|
||||
public List<User> users;
|
||||
}
|
||||
|
||||
public class WSHeaders
|
||||
{
|
||||
public string Host;
|
||||
}
|
||||
|
||||
public class TCPRequestHeaders
|
||||
{
|
||||
public string Host;
|
||||
|
||||
//public string User_Agent = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.75 Safari/537.36";
|
||||
|
||||
public string Accept_Encoding = "gzip, deflate";
|
||||
|
||||
public string Connection = "keep-alive";
|
||||
|
||||
public string Pragma = "no-cache";
|
||||
}
|
||||
|
||||
public class TCPRequest
|
||||
{
|
||||
public string version = "1.1";
|
||||
|
||||
public string method = "GET";
|
||||
|
||||
public string path = "/";
|
||||
|
||||
public TCPRequestHeaders headers;
|
||||
}
|
||||
|
||||
public class TCPHeaders
|
||||
{
|
||||
public string type;
|
||||
|
||||
public TCPRequest request;
|
||||
}
|
||||
|
||||
public class WebSocketSettings
|
||||
{
|
||||
public bool connectionReuse = true;
|
||||
|
||||
public string path = "/";
|
||||
|
||||
public WSHeaders headers;
|
||||
}
|
||||
|
||||
public class TCPSettings
|
||||
{
|
||||
public bool connectionReuse = true;
|
||||
|
||||
public TCPHeaders header;
|
||||
}
|
||||
|
||||
public class QUICSettings
|
||||
{
|
||||
public string security;
|
||||
|
||||
public string key;
|
||||
|
||||
public TCPHeaders header;
|
||||
}
|
||||
|
||||
public class KCPSettings
|
||||
{
|
||||
public int mtu = 1350;
|
||||
|
||||
public int tti = 50;
|
||||
|
||||
public int uplinkCapacity = 12;
|
||||
|
||||
public int downlinkCapacity = 100;
|
||||
|
||||
public bool congestion = false;
|
||||
|
||||
public int readBufferSize = 2;
|
||||
|
||||
public int writeBufferSize = 2;
|
||||
|
||||
public TCPHeaders header;
|
||||
}
|
||||
|
||||
public class HTTPSettings
|
||||
{
|
||||
public string host;
|
||||
|
||||
public string path;
|
||||
}
|
||||
|
||||
public class TLSSettings
|
||||
{
|
||||
public bool allowInsecure = true;
|
||||
}
|
||||
|
||||
public class OutboundSettings
|
||||
{
|
||||
public List<VNext> vnext;
|
||||
}
|
||||
|
||||
public class OutboundMux
|
||||
{
|
||||
public bool enabled = true;
|
||||
}
|
||||
|
||||
public class StreamSettings
|
||||
{
|
||||
public string network;
|
||||
|
||||
public string security;
|
||||
|
||||
public TCPSettings tcpSettings;
|
||||
|
||||
public WebSocketSettings wsSettings;
|
||||
|
||||
public KCPSettings kcpSettings;
|
||||
|
||||
public QUICSettings quicSettings;
|
||||
|
||||
public HTTPSettings httpSettings;
|
||||
|
||||
public TLSSettings tlsSettings;
|
||||
}
|
||||
|
||||
public class Outbounds
|
||||
{
|
||||
public string tag = "proxy";
|
||||
|
||||
public string protocol = "vmess";
|
||||
|
||||
public OutboundSettings settings;
|
||||
|
||||
public StreamSettings streamSettings;
|
||||
|
||||
public OutboundMux mux;
|
||||
}
|
||||
|
||||
public class RoutingRules
|
||||
{
|
||||
public string type = "field";
|
||||
|
||||
public List<string> port;
|
||||
|
||||
public string outboundTag;
|
||||
|
||||
public List<string> ip;
|
||||
|
||||
public List<string> domain;
|
||||
}
|
||||
|
||||
public class Routing
|
||||
{
|
||||
public string domainStrategy = "IPIfNonMatch";
|
||||
|
||||
public List<RoutingRules> rules;
|
||||
}
|
||||
|
||||
public class Config
|
||||
{
|
||||
public List<Inbounds> inbounds;
|
||||
|
||||
public List<Outbounds> outbounds;
|
||||
|
||||
public Routing routing;
|
||||
}
|
||||
}
|
||||
}
|
||||
117
Netch/Models/LegacyServer.cs
Normal file
117
Netch/Models/LegacyServer.cs
Normal file
@@ -0,0 +1,117 @@
|
||||
using System;
|
||||
|
||||
namespace Netch.Models
|
||||
{
|
||||
public class LegacyServer
|
||||
{
|
||||
/// <summary>
|
||||
/// 备注
|
||||
/// </summary>
|
||||
public string Remark;
|
||||
|
||||
/// <summary>
|
||||
/// 组
|
||||
/// </summary>
|
||||
public string Group = "None";
|
||||
|
||||
/// <summary>
|
||||
/// 类型(Socks5、Shadowsocks、ShadowsocksR、VMess)
|
||||
/// </summary>
|
||||
public string Type;
|
||||
|
||||
/// <summary>
|
||||
/// 地址
|
||||
/// </summary>
|
||||
public string Address;
|
||||
|
||||
/// <summary>
|
||||
/// 端口
|
||||
/// </summary>
|
||||
public int Port;
|
||||
|
||||
/// <summary>
|
||||
/// 用户名
|
||||
/// </summary>
|
||||
public string Username;
|
||||
|
||||
/// <summary>
|
||||
/// 密码
|
||||
/// </summary>
|
||||
public string Password;
|
||||
|
||||
/// <summary>
|
||||
/// 用户 ID(V2)
|
||||
/// </summary>
|
||||
public string UserID = String.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 额外 ID(V2)
|
||||
/// </summary>
|
||||
public int AlterID = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 加密方式
|
||||
/// </summary>
|
||||
public string EncryptMethod;
|
||||
|
||||
/// <summary>
|
||||
/// 协议
|
||||
/// </summary>
|
||||
public string Protocol;
|
||||
|
||||
/// <summary>
|
||||
/// 协议参数
|
||||
/// </summary>
|
||||
public string ProtocolParam;
|
||||
|
||||
/// <summary>
|
||||
/// 混淆(SSR)/ 插件(SS)
|
||||
/// </summary>
|
||||
public string OBFS;
|
||||
|
||||
/// <summary>
|
||||
/// 混淆参数(SSR)/ 插件参数(SS)
|
||||
/// </summary>
|
||||
public string OBFSParam;
|
||||
|
||||
/// <summary>
|
||||
/// 传输协议(V2)
|
||||
/// </summary>
|
||||
public string TransferProtocol = "tcp";
|
||||
|
||||
/// <summary>
|
||||
/// 伪装类型(V2)
|
||||
/// </summary>
|
||||
public string FakeType = String.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 伪装域名(V2:HTTP、WebSocket、HTTP/2)
|
||||
/// </summary>
|
||||
public string Host = String.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 传输路径(V2:WebSocket、HTTP/2)
|
||||
/// </summary>
|
||||
public string Path = String.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// QUIC 加密方式(V2)
|
||||
/// </summary>
|
||||
public string QUICSecurity = "none";
|
||||
|
||||
/// <summary>
|
||||
/// QUIC 加密密钥(V2)
|
||||
/// </summary>
|
||||
public string QUICSecret = String.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// TLS 底层传输安全(V2)
|
||||
/// </summary>
|
||||
public bool TLSSecure = false;
|
||||
|
||||
/// <summary>
|
||||
/// 延迟
|
||||
/// </summary>
|
||||
public int Delay = -1;
|
||||
}
|
||||
}
|
||||
60
Netch/Models/LegacySetting.cs
Normal file
60
Netch/Models/LegacySetting.cs
Normal file
@@ -0,0 +1,60 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Netch.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// 用于读取和写入的配置的类
|
||||
/// </summary>
|
||||
public class LegacySetting
|
||||
{
|
||||
/// <summary>
|
||||
/// 服务器选择位置
|
||||
/// </summary>
|
||||
public int ServerComboBoxSelectedIndex = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 模式选择位置
|
||||
/// </summary>
|
||||
public int ModeComboBoxSelectedIndex = 0;
|
||||
|
||||
/// <summary>
|
||||
/// HTTP 本地端口
|
||||
/// </summary>
|
||||
public int HTTPLocalPort = 2802;
|
||||
|
||||
/// <summary>
|
||||
/// Socks5 本地端口
|
||||
/// </summary>
|
||||
public int Socks5LocalPort = 2801;
|
||||
|
||||
/// <summary>
|
||||
/// HTTP 和 Socks5 本地代理地址
|
||||
/// </summary>
|
||||
public string LocalAddress = "127.0.0.1";
|
||||
|
||||
/// <summary>
|
||||
/// Redirector TCP 占用端口
|
||||
/// </summary>
|
||||
public int RedirectorTCPPort = 2800;
|
||||
|
||||
/// <summary>
|
||||
/// TUNTAP 适配器配置
|
||||
/// </summary>
|
||||
public TUNTAPConfig TUNTAP = new TUNTAPConfig();
|
||||
|
||||
/// <summary>
|
||||
/// 服务器列表
|
||||
/// </summary>
|
||||
public List<Models.LegacyServer> Server = new List<Models.LegacyServer>();
|
||||
|
||||
/// <summary>
|
||||
/// 订阅链接列表
|
||||
/// </summary>
|
||||
public List<Models.SubscribeLink> SubscribeLink = new List<Models.SubscribeLink>();
|
||||
|
||||
/// <summary>
|
||||
/// 全局绕过 IP 列表
|
||||
/// </summary>
|
||||
public List<string> BypassIPs = new List<string>();
|
||||
}
|
||||
}
|
||||
120
Netch/Models/Mode.cs
Normal file
120
Netch/Models/Mode.cs
Normal file
@@ -0,0 +1,120 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Netch.Models
|
||||
{
|
||||
public class Mode
|
||||
{
|
||||
/// <summary>
|
||||
/// 备注
|
||||
/// </summary>
|
||||
public string Remark;
|
||||
|
||||
/// <summary>
|
||||
/// 无后缀文件名
|
||||
/// </summary>
|
||||
public string FileName;
|
||||
|
||||
/// <summary>
|
||||
/// 类型
|
||||
/// 0. 进程加速
|
||||
/// 1. TUN/TAP 规则内 IP CIDR 加速
|
||||
/// 2. TUN/TAP 全局,绕过规则内 IP CIDR
|
||||
/// 3. HTTP 代理(自动设置到系统代理)
|
||||
/// 4. Socks5 代理(不自动设置到系统代理)
|
||||
/// 5. Socks5 + HTTP 代理(不自动设置到系统代理)
|
||||
/// </summary>
|
||||
public int Type = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 绕过中国(0. 不绕过 1. 绕过)
|
||||
/// </summary>
|
||||
public bool BypassChina = false;
|
||||
|
||||
/// <summary>
|
||||
/// 规则
|
||||
/// </summary>
|
||||
public List<string> Rule = new List<string>();
|
||||
|
||||
/// <summary>
|
||||
/// 获取备注
|
||||
/// </summary>
|
||||
/// <returns>备注</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
return String.Format("[{0}] {1}", Type + 1, Remark);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取模式文件字符串
|
||||
/// </summary>
|
||||
/// <returns>模式文件字符串</returns>
|
||||
public string ToFileString()
|
||||
{
|
||||
string FileString;
|
||||
|
||||
// 进程模式
|
||||
if (Type == 0)
|
||||
{
|
||||
FileString = $"# {Remark}\r\n";
|
||||
}
|
||||
|
||||
// TUN/TAP 规则内 IP CIDR,无 Bypass China 设置
|
||||
else if (Type == 1)
|
||||
{
|
||||
FileString = $"# {Remark}, {Type}, 0\r\n";
|
||||
}
|
||||
|
||||
// TUN/TAP 全局,绕过规则内 IP CIDR
|
||||
// HTTP 代理(自动设置到系统代理)
|
||||
// Socks5 代理(不自动设置到系统代理)
|
||||
// Socks5 + HTTP 代理(不自动设置到系统代理)
|
||||
else
|
||||
{
|
||||
FileString = $"# {Remark}, {Type}, {(BypassChina ? 1 : 0)}\r\n";
|
||||
}
|
||||
|
||||
foreach (String item in Rule)
|
||||
{
|
||||
FileString = $"{FileString}{item}\r\n";
|
||||
}
|
||||
|
||||
// 去除最后两个多余回车符和换行符
|
||||
FileString = FileString.Substring(0, FileString.Length - 2);
|
||||
|
||||
return FileString;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 写入模式文件
|
||||
/// </summary>
|
||||
public void ToFile(string Dir)
|
||||
{
|
||||
if (!System.IO.Directory.Exists(Dir))
|
||||
{
|
||||
System.IO.Directory.CreateDirectory(Dir);
|
||||
}
|
||||
|
||||
var NewPath = System.IO.Path.Combine(Dir, FileName);
|
||||
if (System.IO.File.Exists(NewPath + ".txt"))
|
||||
{
|
||||
// 重命名该模式文件名
|
||||
NewPath += "_";
|
||||
|
||||
while (System.IO.File.Exists(NewPath + ".txt"))
|
||||
{
|
||||
// 循环重命名该模式文件名,直至不重名
|
||||
NewPath += "_";
|
||||
}
|
||||
}
|
||||
|
||||
FileName = System.IO.Path.GetFileName(NewPath);
|
||||
|
||||
// 加上文件名后缀
|
||||
NewPath += ".txt";
|
||||
|
||||
// 写入到模式文件里
|
||||
System.IO.File.WriteAllText(NewPath, ToFileString());
|
||||
}
|
||||
}
|
||||
}
|
||||
42
Netch/Models/SSD/Main.cs
Normal file
42
Netch/Models/SSD/Main.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Netch.Models.SSD
|
||||
{
|
||||
public class Main
|
||||
{
|
||||
/// <summary>
|
||||
/// 机场名
|
||||
/// </summary>
|
||||
public string airport;
|
||||
|
||||
/// <summary>
|
||||
/// 端口
|
||||
/// </summary>
|
||||
public int port;
|
||||
|
||||
/// <summary>
|
||||
/// 加密方式
|
||||
/// </summary>
|
||||
public string encryption;
|
||||
|
||||
/// <summary>
|
||||
/// 密码
|
||||
/// </summary>
|
||||
public string password;
|
||||
|
||||
/// <summary>
|
||||
/// 插件
|
||||
/// </summary>
|
||||
public string plugin;
|
||||
|
||||
/// <summary>
|
||||
/// 插件参数
|
||||
/// </summary>
|
||||
public string plugin_options;
|
||||
|
||||
/// <summary>
|
||||
/// 服务器数组
|
||||
/// </summary>
|
||||
public List<Server> servers;
|
||||
}
|
||||
}
|
||||
40
Netch/Models/SSD/Server.cs
Normal file
40
Netch/Models/SSD/Server.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
namespace Netch.Models.SSD
|
||||
{
|
||||
public class Server
|
||||
{
|
||||
/// <summary>
|
||||
/// 服务器地址
|
||||
/// </summary>
|
||||
public string server;
|
||||
|
||||
/// <summary>
|
||||
/// 端口
|
||||
/// </summary>
|
||||
public int port;
|
||||
|
||||
/// <summary>
|
||||
/// 加密方式
|
||||
/// </summary>
|
||||
public string encryption;
|
||||
|
||||
/// <summary>
|
||||
/// 密码
|
||||
/// </summary>
|
||||
public string password;
|
||||
|
||||
/// <summary>
|
||||
/// 插件
|
||||
/// </summary>
|
||||
public string plugin;
|
||||
|
||||
/// <summary>
|
||||
/// 插件参数
|
||||
/// </summary>
|
||||
public string plugin_options;
|
||||
|
||||
/// <summary>
|
||||
/// 备注
|
||||
/// </summary>
|
||||
public string remarks;
|
||||
}
|
||||
}
|
||||
220
Netch/Models/Server.cs
Normal file
220
Netch/Models/Server.cs
Normal file
@@ -0,0 +1,220 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Netch.Models
|
||||
{
|
||||
public class Server
|
||||
{
|
||||
/// <summary>
|
||||
/// 备注
|
||||
/// </summary>
|
||||
public string Remark;
|
||||
|
||||
/// <summary>
|
||||
/// 组
|
||||
/// </summary>
|
||||
public string Group = "None";
|
||||
|
||||
/// <summary>
|
||||
/// 代理类型(HTTP、HTTPS、Socks5、SS、SSR、VMess)
|
||||
/// </summary>
|
||||
public string Type;
|
||||
|
||||
/// <summary>
|
||||
/// 倍率
|
||||
/// </summary>
|
||||
public double Rate = 1.0;
|
||||
|
||||
/// <summary>
|
||||
/// 地址
|
||||
/// </summary>
|
||||
public string Hostname;
|
||||
|
||||
/// <summary>
|
||||
/// 端口
|
||||
/// </summary>
|
||||
public int Port;
|
||||
|
||||
/// <summary>
|
||||
/// 账号(HTTP、HTTPS、Socks5)
|
||||
/// </summary>
|
||||
public string Username;
|
||||
|
||||
/// <summary>
|
||||
/// 密码(HTTP、HTTPS、Socks5、SS、SSR)
|
||||
/// </summary>
|
||||
public string Password;
|
||||
|
||||
/// <summary>
|
||||
/// 用户 ID(VMess)
|
||||
/// </summary>
|
||||
public string UserID = String.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 额外 ID(VMess)
|
||||
/// </summary>
|
||||
public int AlterID = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 加密方式(SS、SSR、VMess)
|
||||
/// </summary>
|
||||
public string EncryptMethod;
|
||||
|
||||
/// <summary>
|
||||
/// 插件(SS)
|
||||
/// </summary>
|
||||
public string Plugin;
|
||||
|
||||
/// <summary>
|
||||
/// 插件参数(SS)
|
||||
/// </summary>
|
||||
public string PluginOption;
|
||||
|
||||
/// <summary>
|
||||
/// 协议(SSR)
|
||||
/// </summary>
|
||||
public string Protocol;
|
||||
|
||||
/// <summary>
|
||||
/// 协议参数(SSR)
|
||||
/// </summary>
|
||||
public string ProtocolParam;
|
||||
|
||||
/// <summary>
|
||||
/// 混淆(SSR)
|
||||
/// </summary>
|
||||
public string OBFS;
|
||||
|
||||
/// <summary>
|
||||
/// 混淆参数(SSR)
|
||||
/// </summary>
|
||||
public string OBFSParam;
|
||||
|
||||
/// <summary>
|
||||
/// 传输协议(VMess)
|
||||
/// </summary>
|
||||
public string TransferProtocol = "tcp";
|
||||
|
||||
/// <summary>
|
||||
/// 伪装类型(VMess)
|
||||
/// </summary>
|
||||
public string FakeType = String.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 伪装域名(VMess:HTTP、WebSocket、HTTP/2)
|
||||
/// </summary>
|
||||
public string Host = String.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 传输路径(VMess:WebSocket、HTTP/2)
|
||||
/// </summary>
|
||||
public string Path = String.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// QUIC 加密方式(VMess)
|
||||
/// </summary>
|
||||
public string QUICSecure = "none";
|
||||
|
||||
/// <summary>
|
||||
/// QUIC 加密密钥(VMess)
|
||||
/// </summary>
|
||||
public string QUICSecret = String.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// TLS 底层传输安全(VMess)
|
||||
/// </summary>
|
||||
public bool TLSSecure = false;
|
||||
|
||||
/// <summary>
|
||||
/// 延迟
|
||||
/// </summary>
|
||||
public int Delay = -1;
|
||||
|
||||
/// <summary>
|
||||
/// 获取备注
|
||||
/// </summary>
|
||||
/// <returns>备注</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
if (String.IsNullOrWhiteSpace(Remark))
|
||||
{
|
||||
Remark = $"{Hostname}:{Port}";
|
||||
}
|
||||
|
||||
switch (Type)
|
||||
{
|
||||
case "Socks5":
|
||||
return $"[S5] {Remark}";
|
||||
case "SS":
|
||||
return $"[SS] {Remark}";
|
||||
case "SSR":
|
||||
return $"[SR] {Remark}";
|
||||
case "VMess":
|
||||
return $"[V2] {Remark}";
|
||||
default:
|
||||
return "WTF";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 测试延迟
|
||||
/// </summary>
|
||||
/// <returns>延迟</returns>
|
||||
public int Test()
|
||||
{
|
||||
try
|
||||
{
|
||||
var destination = Utils.DNS.Lookup(Hostname);
|
||||
if (destination == null)
|
||||
{
|
||||
return Delay = -2;
|
||||
}
|
||||
|
||||
var list = new Task<int>[3];
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
list[i] = Task.Run<int>(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var client = new Socket(SocketType.Stream, ProtocolType.Tcp))
|
||||
{
|
||||
var watch = new Stopwatch();
|
||||
watch.Start();
|
||||
|
||||
var task = client.BeginConnect(new IPEndPoint(destination, Port), (result) =>
|
||||
{
|
||||
watch.Stop();
|
||||
}, 0);
|
||||
|
||||
if (task.AsyncWaitHandle.WaitOne(1000))
|
||||
{
|
||||
return (int)watch.ElapsedMilliseconds;
|
||||
}
|
||||
|
||||
return 1000;
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return -4;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Task.WaitAll(list);
|
||||
|
||||
var min = Math.Min(list[0].Result, list[1].Result);
|
||||
min = Math.Min(min, list[2].Result);
|
||||
return Delay = min;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return Delay = -4;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
122
Netch/Models/Setting.cs
Normal file
122
Netch/Models/Setting.cs
Normal file
@@ -0,0 +1,122 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Netch.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// TUN/TAP 适配器配置类
|
||||
/// </summary>
|
||||
public class TUNTAPConfig
|
||||
{
|
||||
/// <summary>
|
||||
/// 地址
|
||||
/// </summary>
|
||||
public string Address = "10.0.236.10";
|
||||
|
||||
/// <summary>
|
||||
/// 掩码
|
||||
/// </summary>
|
||||
public string Netmask = "255.255.255.0";
|
||||
|
||||
/// <summary>
|
||||
/// 网关
|
||||
/// </summary>
|
||||
public string Gateway = "10.0.236.1";
|
||||
|
||||
/// <summary>
|
||||
/// DNS
|
||||
/// </summary>
|
||||
public List<string> DNS = new List<string>();
|
||||
|
||||
/// <summary>
|
||||
/// 使用自定义 DNS 设置
|
||||
/// </summary>
|
||||
public bool UseCustomDNS = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 用于读取和写入的配置的类
|
||||
/// </summary>
|
||||
public class Setting
|
||||
{
|
||||
/// <summary>
|
||||
/// 服务器选择位置
|
||||
/// </summary>
|
||||
public int ServerComboBoxSelectedIndex = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 模式选择位置
|
||||
/// </summary>
|
||||
public int ModeComboBoxSelectedIndex = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 是否关闭窗口时退出
|
||||
/// </summary>
|
||||
public bool ExitWhenClosed = false;
|
||||
|
||||
/// <summary>
|
||||
/// 是否退出时停止
|
||||
/// </summary>
|
||||
public bool StopWhenExited = false;
|
||||
|
||||
/// <summary>
|
||||
/// 是否打开软件时启动加速
|
||||
/// </summary>
|
||||
public bool StartWhenOpened = false;
|
||||
|
||||
/// <summary>
|
||||
/// 是否打开软件时检查更新
|
||||
/// </summary>
|
||||
public bool CheckUpdateWhenOpened = true;
|
||||
|
||||
/// <summary>
|
||||
/// 使用何种模式文件名
|
||||
/// 0 为自定义文件名,1 为使用和备注一致的文件名,2 为使用时间数据作为文件名
|
||||
/// </summary>
|
||||
public int ModeFileNameType = 1;
|
||||
|
||||
/// <summary>
|
||||
/// HTTP 本地端口
|
||||
/// </summary>
|
||||
public int HTTPLocalPort = 2802;
|
||||
|
||||
/// <summary>
|
||||
/// Socks5 本地端口
|
||||
/// </summary>
|
||||
public int Socks5LocalPort = 2801;
|
||||
|
||||
/// <summary>
|
||||
/// Redirector TCP 占用端口
|
||||
/// </summary>
|
||||
public int RedirectorTCPPort = 2800;
|
||||
|
||||
/// <summary>
|
||||
/// HTTP 和 Socks5 本地代理地址
|
||||
/// </summary>
|
||||
public string LocalAddress = "127.0.0.1";
|
||||
|
||||
/// <summary>
|
||||
/// TUNTAP 适配器配置
|
||||
/// </summary>
|
||||
public TUNTAPConfig TUNTAP = new TUNTAPConfig();
|
||||
|
||||
/// <summary>
|
||||
/// 使用代理更新订阅
|
||||
/// </summary>
|
||||
public bool UseProxyToUpdateSubscription = false;
|
||||
|
||||
/// <summary>
|
||||
/// 订阅链接列表
|
||||
/// </summary>
|
||||
public List<Models.SubscribeLink> SubscribeLink = new List<Models.SubscribeLink>();
|
||||
|
||||
/// <summary>
|
||||
/// 服务器列表
|
||||
/// </summary>
|
||||
public List<Models.Server> Server = new List<Models.Server>();
|
||||
|
||||
/// <summary>
|
||||
/// 全局绕过 IP 列表
|
||||
/// </summary>
|
||||
public List<string> BypassIPs = new List<string>();
|
||||
}
|
||||
}
|
||||
39
Netch/Models/State.cs
Normal file
39
Netch/Models/State.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
namespace Netch.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// 状态
|
||||
/// </summary>
|
||||
public enum State
|
||||
{
|
||||
/// <summary>
|
||||
/// 等待命令中
|
||||
/// </summary>
|
||||
Waiting,
|
||||
|
||||
/// <summary>
|
||||
/// 正在启动中
|
||||
/// </summary>
|
||||
Starting,
|
||||
|
||||
/// <summary>
|
||||
/// 已启动
|
||||
/// </summary>
|
||||
Started,
|
||||
|
||||
/// <summary>
|
||||
/// 正在停止中
|
||||
/// </summary>
|
||||
Stopping,
|
||||
|
||||
/// <summary>
|
||||
/// 已停止
|
||||
/// </summary>
|
||||
Stopped,
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 退出中
|
||||
/// </summary>
|
||||
Terminating
|
||||
}
|
||||
}
|
||||
20
Netch/Models/SubscribeLink.cs
Normal file
20
Netch/Models/SubscribeLink.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
namespace Netch.Models
|
||||
{
|
||||
public class SubscribeLink
|
||||
{
|
||||
/// <summary>
|
||||
/// 备注
|
||||
/// </summary>
|
||||
public string Remark;
|
||||
|
||||
/// <summary>
|
||||
/// 链接
|
||||
/// </summary>
|
||||
public string Link;
|
||||
|
||||
/// <summary>
|
||||
/// User Agent
|
||||
/// </summary>
|
||||
public string UserAgent;
|
||||
}
|
||||
}
|
||||
63
Netch/Models/VMess.cs
Normal file
63
Netch/Models/VMess.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
namespace Netch.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// 使用 v2rayN 定义的 VMess 链接格式
|
||||
/// </summary>
|
||||
public class VMess
|
||||
{
|
||||
/// <summary>
|
||||
/// 链接版本
|
||||
/// </summary>
|
||||
public string v;
|
||||
|
||||
/// <summary>
|
||||
/// 备注
|
||||
/// </summary>
|
||||
public string ps;
|
||||
|
||||
/// <summary>
|
||||
/// 地址
|
||||
/// </summary>
|
||||
public string add;
|
||||
|
||||
/// <summary>
|
||||
/// 端口
|
||||
/// </summary>
|
||||
public int port;
|
||||
|
||||
/// <summary>
|
||||
/// 用户 ID
|
||||
/// </summary>
|
||||
public string id;
|
||||
|
||||
/// <summary>
|
||||
/// 额外 ID
|
||||
/// </summary>
|
||||
public int aid = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 传输协议
|
||||
/// </summary>
|
||||
public string net;
|
||||
|
||||
/// <summary>
|
||||
/// 伪装类型
|
||||
/// </summary>
|
||||
public string type;
|
||||
|
||||
/// <summary>
|
||||
/// 伪装域名(HTTP,WS)
|
||||
/// </summary>
|
||||
public string host;
|
||||
|
||||
/// <summary>
|
||||
/// 伪装路径
|
||||
/// </summary>
|
||||
public string path;
|
||||
|
||||
/// <summary>
|
||||
/// 是否使用 TLS
|
||||
/// </summary>
|
||||
public string tls;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user