Compare commits

...

26 Commits

Author SHA1 Message Date
Amazing_DM
4e6bcdcf88 Update UpdateChecker.cs
又又又忘了改版本号
2020-04-23 15:09:00 +08:00
Amazing_DM
f244212cdf :wastebasket:cleanup 2020-04-23 14:56:12 +08:00
Amazing_DM
6649a1fce9 :poop:fix a dns bug? 2020-04-23 14:24:42 +08:00
Amazing_DM
c31338ee1f :sparkles:添加使用代理更新ACL功能
:art:启动后允许打开Netch设置及大部分部分工具栏
2020-04-21 16:58:06 +08:00
Amazing_DM
5f3a300ccc 添加自定义ACL及更新ACL功能 2020-04-16 18:30:36 +08:00
Amazing_DM
bc0e88ae5e Merge pull request #258 from zhuzai123/zhuzai123-patch-1
Update SSRController.cs
2020-04-14 10:14:10 +08:00
Amazing_DM
fac28ca88b Update SSRController.cs 2020-04-14 10:13:59 +08:00
He Houzhu
5efd88b60c Update SSRController.cs
添加ssr启动参数-t 600解决tcp过早超时导致的cod16掉线问题
2020-04-13 10:02:11 +08:00
Amazing_DM
3f59a63766 Update TUNTAPController.cs 2020-04-11 14:08:49 +08:00
Amazing_DM
8f14b030bb 漏掉的版本号 2020-04-08 11:47:45 +08:00
Amazing_DM
f941df0af2 :art:优化驱动更新
:art:Redirector正常启动失败后将尝试停止驱动服务再重新启动
2020-04-08 10:07:25 +08:00
Amazing_DM
13a66d0648 Update NFController.cs 2020-04-05 16:08:58 +08:00
Amazing_DM
9548a3d03a Update NFController.cs 2020-04-04 23:34:58 -05:00
Amazing_DM
c2f33ba15b 2020-04-01 14:37:29 +08:00
Amazing_DM
2895989b13 Update VMessController.cs 2020-04-01 13:20:46 +08:00
Amazing_DM
7cddb75cef Revert "Change STUN Server"
This reverts commit c39b758fe6.
2020-03-31 00:50:36 +08:00
Amazing_DM
f05ae498c6 :art:安装Tap driver时留出一点时间 防止找不到适配器ID 2020-03-30 16:00:27 +08:00
Amazing_DM
ff0fe2ab9f Update submodule 2020-03-30 15:41:45 +08:00
Amazing_DM
764e78d662 Update UpdateChecker.cs 2020-03-30 15:31:34 +08:00
Amazing_DM
bdaab4f1ac 此处修复一个诡异的BUG 感谢@ColinWood Tap模式 Mux不能为Null 否则Netch内存占用极大 2020-03-27 12:03:31 +08:00
Amazing_DM
9ad5e16f47 Update submodule 2020-03-26 14:48:30 +08:00
Amazing_DM
c861ed4116 Merge pull request #256 from VCStardust/master
Change STUN Test Server
2020-03-25 21:57:45 -05:00
Col. Schwi
c39b758fe6 Change STUN Server 2020-03-25 21:28:15 +08:00
Amazing_DM
e1901587a5 :art:订阅更新超时改为10s
:art:微调设置界面
2020-03-24 18:29:46 +08:00
Amazing_DM
8aea21a2c6 :bug:fix a bug. catch复制链接按钮 2020-03-23 14:43:38 +08:00
Amazing_DM
d97d461354 :art:改进SSR链接解析 2020-03-23 14:40:22 +08:00
26 changed files with 572 additions and 242 deletions

View File

@@ -2,8 +2,6 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Threading;
namespace Netch.Controllers
{
@@ -15,23 +13,23 @@ namespace Netch.Controllers
public Process Instance;
/// <summary>
/// 启动NatTypeTester
/// 启动DNS服务
/// </summary>
/// <returns></returns>
public bool Start()
{
MainForm.Instance.StatusText($"{Utils.i18N.Translate("Starting dns2tcp Service")}");
MainForm.Instance.StatusText($"{Utils.i18N.Translate("Starting dns Service")}");
try
{
if (!File.Exists("bin\\dns2tcp.exe"))
if (!File.Exists("bin\\unbound.exe") && !File.Exists("bin\\unbound-service.conf") && !File.Exists("bin\\forward-zone.conf"))
{
return false;
}
Instance = MainController.GetProcess();
Instance.StartInfo.FileName = "bin\\dns2tcp.exe";
Instance.StartInfo.FileName = "bin\\unbound.exe";
Instance.StartInfo.Arguments = " -L 127.0.0.1:53 -R 1.1.1.1:53";
Instance.StartInfo.Arguments = "-c unbound-service.conf -v";
Instance.OutputDataReceived += OnOutputDataReceived;
Instance.ErrorDataReceived += OnOutputDataReceived;
@@ -43,7 +41,7 @@ namespace Netch.Controllers
}
catch (Exception)
{
Utils.Logging.Info("dns2tcp 进程出错");
Utils.Logging.Info("dns-unbound 进程出错");
Stop();
return false;
}
@@ -71,42 +69,12 @@ namespace Netch.Controllers
{
if (!string.IsNullOrWhiteSpace(e.Data))
{
if (File.Exists("logging\\dns2tcp.log"))
if (File.Exists("logging\\dns-unbound.log"))
{
File.Delete("logging\\dns2tcp.log");
File.Delete("logging\\dns-unbound.log");
}
File.AppendAllText("logging\\dns2tcp.log", $"{e.Data}\r\n");
File.AppendAllText("logging\\dns-unbound.log", $"{e.Data}\r\n");
}
}
/* public static DNS.Server.DnsServer Server = new DNS.Server.DnsServer(new Resolver());
public bool Start()
{
MainForm.Instance.StatusText($"{Utils.i18N.Translate("Status")}{Utils.i18N.Translate(": ")}{Utils.i18N.Translate("Starting LocalDns service")}");
try
{
_ = Server.Listen(new IPEndPoint(IPAddress.IPv6Any, 53));
}
catch (Exception e)
{
Utils.Logging.Info(e.ToString());
return false;
}
return true;
}
public void Stop()
{
try
{
Server.Dispose();
}
catch (Exception e)
{
Utils.Logging.Info(e.ToString());
}
}*/
}
}

View File

@@ -1,5 +1,4 @@
using System;
using Microsoft.Win32;
namespace Netch.Controllers
{

View File

@@ -1,8 +1,8 @@
using System;
using Netch.Forms;
using System;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
namespace Netch.Controllers
@@ -123,7 +123,14 @@ namespace Netch.Controllers
pNTTController = new NTTController();
}
// 进程代理模式,启动 NF 控制器
result = pNFController.Start(server, mode);
result = pNFController.Start(server, mode, false);
if (!result)
{
MainForm.Instance.StatusText($"{Utils.i18N.Translate("Status")}{Utils.i18N.Translate(": ")}{Utils.i18N.Translate("ReStarting Redirector")}");
Utils.Logging.Info("正常启动失败后尝试停止驱动服务再重新启动");
//正常启动失败后尝试停止驱动服务再重新启动
result = pNFController.Start(server, mode, true);
}
if (result)
Task.Run(() =>
{

View File

@@ -40,18 +40,45 @@ namespace Netch.Controllers
/// </summary>
/// <param name="server">服务器</param>
/// <param name="mode">模式</param>
/// <param name="StopServiceAndRestart">先停止驱动服务再重新启动</param>
/// <returns>是否成功</returns>
public bool Start(Models.Server server, Models.Mode mode)
public bool Start(Models.Server server, Models.Mode mode, bool StopServiceAndRestart)
{
MainForm.Instance.StatusText($"{Utils.i18N.Translate("Status")}{Utils.i18N.Translate(": ")}{Utils.i18N.Translate("Starting Redirector")}");
if (!StopServiceAndRestart)
MainForm.Instance.StatusText($"{Utils.i18N.Translate("Status")}{Utils.i18N.Translate(": ")}{Utils.i18N.Translate("Starting Redirector")}");
// 检查驱动是否存在
if (File.Exists(driverPath))
{
//检查驱动版本
FileVersionInfo fileVerInfo = System.Diagnostics.FileVersionInfo.GetVersionInfo(driverPath);
if (new Version(fileVerInfo.FileVersion) < new Version(UpdateChecker.NFDriverVersion))
// 生成系统版本
var version = $"{Environment.OSVersion.Version.Major.ToString()}.{Environment.OSVersion.Version.Minor.ToString()}";
var driverName = "";
switch (version)
{
case "10.0":
driverName = "Win-10.sys";
break;
case "6.3":
case "6.2":
driverName = "Win-8.sys";
break;
case "6.1":
case "6.0":
driverName = "Win-7.sys";
break;
default:
Utils.Logging.Info($"不支持的系统版本:{version}");
return false;
}
//检查驱动版本号
FileVersionInfo SystemfileVerInfo = System.Diagnostics.FileVersionInfo.GetVersionInfo(driverPath);
FileVersionInfo BinFileVerInfo = System.Diagnostics.FileVersionInfo.GetVersionInfo(string.Format("bin\\{0}", driverName));
if (!SystemfileVerInfo.FileVersion.Equals(BinFileVerInfo.FileVersion))
{
Utils.Logging.Info("开始更新驱动");
//需要更新驱动
try
{
@@ -67,6 +94,8 @@ namespace Netch.Controllers
File.Delete(driverPath);
if (!InstallDriver())
return false;
Utils.Logging.Info($"驱动更新完毕,当前驱动版本:{BinFileVerInfo.FileVersion}");
}
catch (Exception)
{
@@ -86,12 +115,13 @@ namespace Netch.Controllers
{
//启动驱动服务
var service = new ServiceController("netfilter2");
if (service.Status == ServiceControllerStatus.Running)
if (service.Status == ServiceControllerStatus.Running && StopServiceAndRestart)
{
//防止其他程序占用 重置NF百万ID限制 待定
/*service.Stop();
//防止其他程序占用 重置NF百万ID限制
service.Stop();
service.WaitForStatus(ServiceControllerStatus.Stopped);
MainForm.Instance.StatusText($"{Utils.i18N.Translate("Status")}{Utils.i18N.Translate(": ")}{Utils.i18N.Translate("Starting netfilter2 Service")}");
service.Start();*/
service.Start();
}
else if (service.Status == ServiceControllerStatus.Stopped)
{
@@ -207,12 +237,11 @@ namespace Netch.Controllers
}
}
Utils.Logging.Info($"{fallback}");
if (File.Exists("logging\\redirector.log"))
File.Delete("logging\\redirector.log");
Instance.StartInfo.Arguments = fallback;
Instance.StartInfo.Arguments = fallback + $" -tcport {Global.Settings.RedirectorTCPPort}";
Utils.Logging.Info(Instance.StartInfo.Arguments);
Instance.OutputDataReceived += OnOutputDataReceived;
Instance.ErrorDataReceived += OnOutputDataReceived;
State = Models.State.Starting;
@@ -220,14 +249,19 @@ namespace Netch.Controllers
Instance.BeginOutputReadLine();
Instance.BeginErrorReadLine();
for (var i = 0; i < 1000; i++)
for (var i = 0; i < 10; i++)
{
Thread.Sleep(10);
Thread.Sleep(1000);
if (State == Models.State.Started)
{
Utils.Logging.Info($"成功启动Redirector耗时:{i + 1}秒");
return true;
}
else
{
Utils.Logging.Info($"Redirector启动中已耗时:{i + 1}秒");
}
}
Utils.Logging.Info("NF 进程启动超时");
@@ -256,6 +290,7 @@ namespace Netch.Controllers
public bool InstallDriver()
{
Utils.Logging.Info("安装驱动中");
// 生成系统版本
var version = $"{Environment.OSVersion.Version.Major.ToString()}.{Environment.OSVersion.Version.Minor.ToString()}";
@@ -344,4 +379,4 @@ namespace Netch.Controllers
}
}
}
}
}

View File

@@ -43,7 +43,7 @@ namespace Netch.Controllers
{
Instance.StartInfo.Arguments = $"-s {server.Hostname} -p {server.Port} -b {Global.Settings.LocalAddress} -l {Global.Settings.Socks5LocalPort} -m {server.EncryptMethod} -k \"{server.Password}\" -u";
}
if (mode.BypassChina)
{
Instance.StartInfo.Arguments += " --acl default.acl";

View File

@@ -34,7 +34,7 @@ namespace Netch.Controllers
Instance = MainController.GetProcess();
Instance.StartInfo.FileName = "bin\\ShadowsocksR.exe";
Instance.StartInfo.Arguments = $"-s {server.Hostname} -p {server.Port} -k \"{server.Password}\" -m {server.EncryptMethod}";
Instance.StartInfo.Arguments = $"-s {server.Hostname} -p {server.Port} -k \"{server.Password}\" -m {server.EncryptMethod} -t 600";
if (!string.IsNullOrEmpty(server.Protocol))
{

View File

@@ -1,12 +1,12 @@
using System;
using Netch.Forms;
using Netch.Utils;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Text;
using System.Threading;
using Netch.Forms;
using Netch.Utils;
namespace Netch.Controllers
{
@@ -39,7 +39,7 @@ namespace Netch.Controllers
public DNSController pDNSController = new DNSController();
// ByPassLan IP
List<string> BypassLanIPs = new List<string>() { "10.0.0.0/8", "172.16.0.0/16", "192.168.0.0/24" };
List<string> BypassLanIPs = new List<string>() { "10.0.0.0/8", "172.16.0.0/16", "192.168.0.0/16" };
/// <summary>
/// 配置 TUNTAP 适配器

View File

@@ -1,10 +1,10 @@
using System;
using Netch.Models.GitHubRelease;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Net.Http;
using System.Threading.Tasks;
using Netch.Models.GitHubRelease;
using Newtonsoft.Json;
namespace Netch.Controllers
{
@@ -26,8 +26,7 @@ namespace Netch.Controllers
public const string Name = @"Netch";
public const string Copyright = @"Copyright © 2019 - 2020";
public const string Version = @"1.4.0";
public const string NFDriverVersion = @"1.5.9.0";
public const string Version = @"1.4.2";
public async void Check(bool notifyNoFound, bool isPreRelease)
{

View File

@@ -126,14 +126,6 @@ namespace Netch.Controllers
{
enabled = server.UseMux
}
},
new Models.Information.VMess.Outbounds
{
tag = "direct",
protocol = "freedom",
settings = null,
streamSettings = null,
mux = null
}
},
routing = new Models.Information.VMess.Routing
@@ -147,7 +139,7 @@ namespace Netch.Controllers
{
"geoip:cn",
"geoip:private"
},
domain = new List<string>
{

View File

@@ -50,8 +50,10 @@ namespace Netch.Forms
this.RestartServiceToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.UninstallServiceToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.CleanDNSCacheToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.UpdateACLToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.AboutToolStripButton = new System.Windows.Forms.ToolStripButton();
this.VersionLabel = new System.Windows.Forms.ToolStripLabel();
this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.ConfigurationGroupBox = new System.Windows.Forms.GroupBox();
this.configLayoutPanel = new System.Windows.Forms.TableLayoutPanel();
this.ProfileLabel = new System.Windows.Forms.Label();
@@ -82,6 +84,7 @@ namespace Netch.Forms
this.SettingsButton = new System.Windows.Forms.Button();
this.ProfileGroupBox = new System.Windows.Forms.GroupBox();
this.ProfileTable = new System.Windows.Forms.TableLayoutPanel();
this.updateACLWithProxyToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.MenuStrip.SuspendLayout();
this.ConfigurationGroupBox.SuspendLayout();
this.configLayoutPanel.SuspendLayout();
@@ -108,7 +111,8 @@ namespace Netch.Forms
this.SubscribeToolStripMenuItem,
this.OptionsToolStripMenuItem,
this.AboutToolStripButton,
this.VersionLabel});
this.VersionLabel,
this.exitToolStripMenuItem});
this.MenuStrip.Location = new System.Drawing.Point(0, 0);
this.MenuStrip.Name = "MenuStrip";
this.MenuStrip.RenderMode = System.Windows.Forms.ToolStripRenderMode.Professional;
@@ -217,7 +221,9 @@ namespace Netch.Forms
this.ReloadModesToolStripMenuItem,
this.RestartServiceToolStripMenuItem,
this.UninstallServiceToolStripMenuItem,
this.CleanDNSCacheToolStripMenuItem});
this.CleanDNSCacheToolStripMenuItem,
this.UpdateACLToolStripMenuItem,
this.updateACLWithProxyToolStripMenuItem});
this.OptionsToolStripMenuItem.Margin = new System.Windows.Forms.Padding(0, 0, 0, 1);
this.OptionsToolStripMenuItem.Name = "OptionsToolStripMenuItem";
this.OptionsToolStripMenuItem.Size = new System.Drawing.Size(66, 21);
@@ -226,31 +232,38 @@ namespace Netch.Forms
// ReloadModesToolStripMenuItem
//
this.ReloadModesToolStripMenuItem.Name = "ReloadModesToolStripMenuItem";
this.ReloadModesToolStripMenuItem.Size = new System.Drawing.Size(177, 22);
this.ReloadModesToolStripMenuItem.Size = new System.Drawing.Size(209, 22);
this.ReloadModesToolStripMenuItem.Text = "Reload Modes";
this.ReloadModesToolStripMenuItem.Click += new System.EventHandler(this.ReloadModesToolStripMenuItem_Click);
//
// RestartServiceToolStripMenuItem
//
this.RestartServiceToolStripMenuItem.Name = "RestartServiceToolStripMenuItem";
this.RestartServiceToolStripMenuItem.Size = new System.Drawing.Size(177, 22);
this.RestartServiceToolStripMenuItem.Size = new System.Drawing.Size(209, 22);
this.RestartServiceToolStripMenuItem.Text = "Restart Service";
this.RestartServiceToolStripMenuItem.Click += new System.EventHandler(this.RestartServiceToolStripMenuItem_Click);
//
// UninstallServiceToolStripMenuItem
//
this.UninstallServiceToolStripMenuItem.Name = "UninstallServiceToolStripMenuItem";
this.UninstallServiceToolStripMenuItem.Size = new System.Drawing.Size(177, 22);
this.UninstallServiceToolStripMenuItem.Size = new System.Drawing.Size(209, 22);
this.UninstallServiceToolStripMenuItem.Text = "Uninstall Service";
this.UninstallServiceToolStripMenuItem.Click += new System.EventHandler(this.UninstallServiceToolStripMenuItem_Click);
//
// CleanDNSCacheToolStripMenuItem
//
this.CleanDNSCacheToolStripMenuItem.Name = "CleanDNSCacheToolStripMenuItem";
this.CleanDNSCacheToolStripMenuItem.Size = new System.Drawing.Size(177, 22);
this.CleanDNSCacheToolStripMenuItem.Size = new System.Drawing.Size(209, 22);
this.CleanDNSCacheToolStripMenuItem.Text = "Clean DNS Cache";
this.CleanDNSCacheToolStripMenuItem.Click += new System.EventHandler(this.CleanDNSCacheToolStripMenuItem_Click);
//
// UpdateACLToolStripMenuItem
//
this.UpdateACLToolStripMenuItem.Name = "UpdateACLToolStripMenuItem";
this.UpdateACLToolStripMenuItem.Size = new System.Drawing.Size(209, 22);
this.UpdateACLToolStripMenuItem.Text = "Update ACL";
this.UpdateACLToolStripMenuItem.Click += new System.EventHandler(this.updateACLToolStripMenuItem_Click);
//
// AboutToolStripButton
//
this.AboutToolStripButton.Alignment = System.Windows.Forms.ToolStripItemAlignment.Right;
@@ -273,6 +286,13 @@ namespace Netch.Forms
this.VersionLabel.Text = "x.x.x";
this.VersionLabel.Click += new System.EventHandler(this.VersionLabel_Click);
//
// exitToolStripMenuItem
//
this.exitToolStripMenuItem.Name = "exitToolStripMenuItem";
this.exitToolStripMenuItem.Size = new System.Drawing.Size(40, 22);
this.exitToolStripMenuItem.Text = "Exit";
this.exitToolStripMenuItem.Click += new System.EventHandler(this.exitToolStripMenuItem_Click);
//
// ConfigurationGroupBox
//
this.ConfigurationGroupBox.Controls.Add(this.configLayoutPanel);
@@ -602,6 +622,13 @@ namespace Netch.Forms
this.ProfileTable.Size = new System.Drawing.Size(599, 43);
this.ProfileTable.TabIndex = 0;
//
// updateACLWithProxyToolStripMenuItem
//
this.updateACLWithProxyToolStripMenuItem.Name = "updateACLWithProxyToolStripMenuItem";
this.updateACLWithProxyToolStripMenuItem.Size = new System.Drawing.Size(209, 22);
this.updateACLWithProxyToolStripMenuItem.Text = "Update ACL with proxy";
this.updateACLWithProxyToolStripMenuItem.Click += new System.EventHandler(this.updateACLWithProxyToolStripMenuItem_Click);
//
// MainForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
@@ -698,5 +725,8 @@ namespace Netch.Forms
private System.Windows.Forms.TableLayoutPanel configLayoutPanel;
private System.Windows.Forms.TableLayoutPanel tableLayoutPanel2;
private System.Windows.Forms.TableLayoutPanel tableLayoutPanel3;
private System.Windows.Forms.ToolStripMenuItem UpdateACLToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem exitToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem updateACLWithProxyToolStripMenuItem;
}
}

View File

@@ -325,10 +325,12 @@ namespace Netch.Forms
ManageSubscribeLinksToolStripMenuItem.Text = Utils.i18N.Translate(ManageSubscribeLinksToolStripMenuItem.Text);
UpdateServersFromSubscribeLinksToolStripMenuItem.Text = Utils.i18N.Translate(UpdateServersFromSubscribeLinksToolStripMenuItem.Text);
OptionsToolStripMenuItem.Text = Utils.i18N.Translate(OptionsToolStripMenuItem.Text);
exitToolStripMenuItem.Text = Utils.i18N.Translate(exitToolStripMenuItem.Text);
RestartServiceToolStripMenuItem.Text = Utils.i18N.Translate(RestartServiceToolStripMenuItem.Text);
UninstallServiceToolStripMenuItem.Text = Utils.i18N.Translate(UninstallServiceToolStripMenuItem.Text);
ReloadModesToolStripMenuItem.Text = Utils.i18N.Translate(ReloadModesToolStripMenuItem.Text);
CleanDNSCacheToolStripMenuItem.Text = Utils.i18N.Translate(CleanDNSCacheToolStripMenuItem.Text);
UpdateACLToolStripMenuItem.Text = Utils.i18N.Translate(UpdateACLToolStripMenuItem.Text);
AboutToolStripButton.Text = Utils.i18N.Translate(AboutToolStripButton.Text);
ConfigurationGroupBox.Text = Utils.i18N.Translate(ConfigurationGroupBox.Text);
ServerLabel.Text = Utils.i18N.Translate(ServerLabel.Text);
@@ -791,7 +793,14 @@ namespace Netch.Forms
return;
}
MenuStrip.Enabled = ConfigurationGroupBox.Enabled = ControlButton.Enabled = SettingsButton.Enabled = false;
//MenuStrip.Enabled = ConfigurationGroupBox.Enabled = ControlButton.Enabled = SettingsButton.Enabled = false;
//关闭启动按钮
ControlButton.Enabled = false;
//关闭使用代理更新ACL
updateACLWithProxyToolStripMenuItem.Enabled = false;
UpdateServersFromSubscribeLinksToolStripMenuItem.Enabled = false;
ControlButton.Text = "...";
StatusLabel.Text = $"{Utils.i18N.Translate("Status")}{Utils.i18N.Translate(": ")}{Utils.i18N.Translate("Starting")}";
State = Models.State.Starting;
@@ -885,8 +894,8 @@ namespace Netch.Forms
if (State == Models.State.Started)
{
server.Test();
// 重载服务器列表
InitServer();
// 重载服务器列表
InitServer();
Thread.Sleep(Global.Settings.StartedTcping_Interval * 1000);
}
@@ -1254,7 +1263,15 @@ namespace Netch.Forms
if (ServerComboBox.SelectedIndex != -1)
{
var selectedMode = (Models.Server)ServerComboBox.SelectedItem;
Clipboard.SetText(Utils.ShareLink.GetShareLink(selectedMode));
try
{
//听说巨硬BUG经常会炸所以Catch一下 :D
Clipboard.SetText(Utils.ShareLink.GetShareLink(selectedMode));
}
catch (Exception)
{
}
}
else
{
@@ -1276,5 +1293,126 @@ namespace Netch.Forms
NatTypeStatusLabel.Text = "NAT" + Utils.i18N.Translate(": ") + Utils.i18N.Translate("Test failed");
}
}
private void updateACLToolStripMenuItem_Click(object sender, EventArgs e)
{
using var client = new Override.WebClient();
client.DownloadFileTaskAsync(Global.Settings.ACL, "bin\\default.acl");
client.DownloadFileCompleted += ((sender, args) =>
{
try
{
if (args.Error == null)
{
NotifyIcon.ShowBalloonTip(5,
UpdateChecker.Name, Utils.i18N.Translate("ACL updated successfully"),
ToolTipIcon.Info);
//MessageBox.Show(Utils.i18N.Translate("ACL updated successfully"));
}
else
{
Utils.Logging.Info("ACL更新失败" + args.Error);
NotifyIcon.ShowBalloonTip(5,
UpdateChecker.Name,
Utils.i18N.Translate("ACL update failed"),
ToolTipIcon.Error);
//MessageBox.Show(Utils.i18N.Translate("ACL update failed"));
}
}
finally
{
StatusText($"{Utils.i18N.Translate("Status")}{Utils.i18N.Translate(": ")}{Utils.i18N.Translate("Waiting for command")}");
}
});
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
// 当前状态如果不是已停止状态
if (State != Models.State.Waiting && State != Models.State.Stopped)
{
// 如果未勾选退出时停止,要求先点击停止按钮
if (!Global.Settings.StopWhenExited)
{
MessageBox.Show(Utils.i18N.Translate("Please press Stop button first"), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
Visible = true;
ShowInTaskbar = true; // 显示在系统任务栏
WindowState = FormWindowState.Normal; // 还原窗体
NotifyIcon.Visible = true; // 托盘图标隐藏
return;
}
// 否则直接调用停止按钮的方法
ControlButton_Click(sender, e);
}
SaveConfigs();
State = Models.State.Terminating;
NotifyIcon.Visible = false;
Close();
Dispose();
Environment.Exit(Environment.ExitCode);
}
private void updateACLWithProxyToolStripMenuItem_Click(object sender, EventArgs e)
{
updateACLWithProxyToolStripMenuItem.Enabled = false;
if (Global.Settings.UseProxyToUpdateSubscription)
{
// 当前 ServerComboBox 中至少有一项
if (ServerComboBox.SelectedIndex == -1)
{
MessageBox.Show(Utils.i18N.Translate("Please select a server first"), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
MenuStrip.Enabled = ConfigurationGroupBox.Enabled = ControlButton.Enabled = SettingsButton.Enabled = false;
ControlButton.Text = "...";
}
Task.Run(() =>
{
var mode = new Models.Mode
{
Remark = "ProxyUpdate",
Type = 5
};
MainController = new MainController();
MainController.Start(ServerComboBox.SelectedItem as Models.Server, mode);
using var client = new Override.WebClient();
client.Proxy = new System.Net.WebProxy($"http://127.0.0.1:{Global.Settings.HTTPLocalPort}");
StatusText($"{Utils.i18N.Translate("Status")}{Utils.i18N.Translate(": ")}{Utils.i18N.Translate("Updating in the background")}");
try
{
client.DownloadFile(Global.Settings.ACL, "bin\\default.acl");
NotifyIcon.ShowBalloonTip(5,
UpdateChecker.Name, Utils.i18N.Translate("ACL updated successfully"),
ToolTipIcon.Info);
}
catch (Exception e)
{
Utils.Logging.Info("ACL更新失败" + e.Message);
NotifyIcon.ShowBalloonTip(5,
UpdateChecker.Name,
Utils.i18N.Translate("ACL update failed"),
ToolTipIcon.Error);
}
finally
{
updateACLWithProxyToolStripMenuItem.Enabled = true;
StatusText($"{Utils.i18N.Translate("Status")}{Utils.i18N.Translate(": ")}{Utils.i18N.Translate("Waiting for command")}");
MainController.Stop();
}
});
}
}
}

View File

@@ -30,6 +30,8 @@
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(SettingForm));
this.PortGroupBox = new System.Windows.Forms.GroupBox();
this.RedirectorLabel = new System.Windows.Forms.Label();
this.RedirectorTextBox = new System.Windows.Forms.TextBox();
this.AllowDevicesCheckBox = new System.Windows.Forms.CheckBox();
this.HTTPPortLabel = new System.Windows.Forms.Label();
this.HTTPPortTextBox = new System.Windows.Forms.TextBox();
@@ -68,6 +70,8 @@
this.StartWhenOpenedCheckBox = new System.Windows.Forms.CheckBox();
this.StopWhenExitedCheckBox = new System.Windows.Forms.CheckBox();
this.ExitWhenClosedCheckBox = new System.Windows.Forms.CheckBox();
this.AclAddr = new System.Windows.Forms.TextBox();
this.AclLabel = new System.Windows.Forms.Label();
this.PortGroupBox.SuspendLayout();
this.TUNTAPGroupBox.SuspendLayout();
this.BehaviorGroupBox.SuspendLayout();
@@ -75,6 +79,8 @@
//
// PortGroupBox
//
this.PortGroupBox.Controls.Add(this.RedirectorLabel);
this.PortGroupBox.Controls.Add(this.RedirectorTextBox);
this.PortGroupBox.Controls.Add(this.AllowDevicesCheckBox);
this.PortGroupBox.Controls.Add(this.HTTPPortLabel);
this.PortGroupBox.Controls.Add(this.HTTPPortTextBox);
@@ -87,10 +93,27 @@
this.PortGroupBox.TabStop = false;
this.PortGroupBox.Text = "Local Port";
//
// RedirectorLabel
//
this.RedirectorLabel.AutoSize = true;
this.RedirectorLabel.Location = new System.Drawing.Point(9, 83);
this.RedirectorLabel.Name = "RedirectorLabel";
this.RedirectorLabel.Size = new System.Drawing.Size(95, 17);
this.RedirectorLabel.TabIndex = 6;
this.RedirectorLabel.Text = "Redirector TCP";
//
// RedirectorTextBox
//
this.RedirectorTextBox.Location = new System.Drawing.Point(120, 80);
this.RedirectorTextBox.Name = "RedirectorTextBox";
this.RedirectorTextBox.Size = new System.Drawing.Size(294, 23);
this.RedirectorTextBox.TabIndex = 7;
this.RedirectorTextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
//
// AllowDevicesCheckBox
//
this.AllowDevicesCheckBox.AutoSize = true;
this.AllowDevicesCheckBox.Location = new System.Drawing.Point(120, 80);
this.AllowDevicesCheckBox.Location = new System.Drawing.Point(120, 109);
this.AllowDevicesCheckBox.Name = "AllowDevicesCheckBox";
this.AllowDevicesCheckBox.Size = new System.Drawing.Size(206, 21);
this.AllowDevicesCheckBox.TabIndex = 5;
@@ -264,6 +287,8 @@
//
// BehaviorGroupBox
//
this.BehaviorGroupBox.Controls.Add(this.AclAddr);
this.BehaviorGroupBox.Controls.Add(this.AclLabel);
this.BehaviorGroupBox.Controls.Add(this.DetectionInterval_Label);
this.BehaviorGroupBox.Controls.Add(this.DetectionInterval_TextBox);
this.BehaviorGroupBox.Controls.Add(this.EnableStartedTcping_CheckBox);
@@ -329,7 +354,7 @@
// BypassModeCheckBox
//
this.BypassModeCheckBox.AutoSize = true;
this.BypassModeCheckBox.Location = new System.Drawing.Point(276, 232);
this.BypassModeCheckBox.Location = new System.Drawing.Point(276, 307);
this.BypassModeCheckBox.Name = "BypassModeCheckBox";
this.BypassModeCheckBox.Size = new System.Drawing.Size(135, 21);
this.BypassModeCheckBox.TabIndex = 14;
@@ -340,7 +365,7 @@
// Redirector2checkBox
//
this.Redirector2checkBox.AutoSize = true;
this.Redirector2checkBox.Location = new System.Drawing.Point(152, 232);
this.Redirector2checkBox.Location = new System.Drawing.Point(152, 306);
this.Redirector2checkBox.Name = "Redirector2checkBox";
this.Redirector2checkBox.Size = new System.Drawing.Size(118, 21);
this.Redirector2checkBox.TabIndex = 11;
@@ -350,7 +375,7 @@
// ExperimentalFunction_Label
//
this.ExperimentalFunction_Label.AutoSize = true;
this.ExperimentalFunction_Label.Location = new System.Drawing.Point(6, 233);
this.ExperimentalFunction_Label.Location = new System.Drawing.Point(6, 307);
this.ExperimentalFunction_Label.Name = "ExperimentalFunction_Label";
this.ExperimentalFunction_Label.Size = new System.Drawing.Size(133, 17);
this.ExperimentalFunction_Label.TabIndex = 13;
@@ -358,7 +383,7 @@
//
// STUN_ServerPortTextBox
//
this.STUN_ServerPortTextBox.Location = new System.Drawing.Point(117, 203);
this.STUN_ServerPortTextBox.Location = new System.Drawing.Point(117, 206);
this.STUN_ServerPortTextBox.Name = "STUN_ServerPortTextBox";
this.STUN_ServerPortTextBox.Size = new System.Drawing.Size(294, 23);
this.STUN_ServerPortTextBox.TabIndex = 8;
@@ -471,6 +496,23 @@
this.ExitWhenClosedCheckBox.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
this.ExitWhenClosedCheckBox.UseVisualStyleBackColor = true;
//
// AclAddr
//
this.AclAddr.Location = new System.Drawing.Point(117, 235);
this.AclAddr.Name = "AclAddr";
this.AclAddr.Size = new System.Drawing.Size(294, 23);
this.AclAddr.TabIndex = 19;
this.AclAddr.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
//
// AclLabel
//
this.AclLabel.AutoSize = true;
this.AclLabel.Location = new System.Drawing.Point(6, 238);
this.AclLabel.Name = "AclLabel";
this.AclLabel.Size = new System.Drawing.Size(78, 17);
this.AclLabel.TabIndex = 20;
this.AclLabel.Text = "Custom ACL";
//
// SettingForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
@@ -542,5 +584,9 @@
private System.Windows.Forms.CheckBox EnableStartedTcping_CheckBox;
private System.Windows.Forms.Label DelayTestAfterStartup_Label;
private System.Windows.Forms.Label DetectionInterval_Label;
private System.Windows.Forms.Label RedirectorLabel;
private System.Windows.Forms.TextBox RedirectorTextBox;
private System.Windows.Forms.TextBox AclAddr;
private System.Windows.Forms.Label AclLabel;
}
}

View File

@@ -1,5 +1,4 @@
using System;
using System.Collections;
using System.Net;
using System.Windows.Forms;
using TaskScheduler;
@@ -69,6 +68,7 @@ namespace Netch.Forms
Socks5PortTextBox.Text = Global.Settings.Socks5LocalPort.ToString();
HTTPPortTextBox.Text = Global.Settings.HTTPLocalPort.ToString();
RedirectorTextBox.Text = Global.Settings.RedirectorTCPPort.ToString();
TUNTAPAddressTextBox.Text = Global.Settings.TUNTAP.Address;
TUNTAPNetmaskTextBox.Text = Global.Settings.TUNTAP.Netmask;
@@ -95,6 +95,9 @@ namespace Netch.Forms
STUN_ServerTextBox.Text = Global.Settings.STUN_Server.ToString();
STUN_ServerPortTextBox.Text = Global.Settings.STUN_Server_Port.ToString();
AclLabel.Text = Utils.i18N.Translate(AclLabel.Text);
AclAddr.Text = Global.Settings.ACL.ToString();
if (Global.Settings.TUNTAP.DNS.Count > 0)
{
var dns = "";
@@ -238,6 +241,27 @@ namespace Netch.Forms
return;
}
try
{
var RedirectorPort = int.Parse(RedirectorTextBox.Text);
if (RedirectorPort > 0 && RedirectorPort < 65536)
{
Global.Settings.RedirectorTCPPort = RedirectorPort;
}
else
{
throw new FormatException();
}
}
catch (FormatException)
{
RedirectorTextBox.Text = Global.Settings.RedirectorTCPPort.ToString();
MessageBox.Show(Utils.i18N.Translate("Port value illegal. Try again."), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
if (AllowDevicesCheckBox.Checked)
{
Global.Settings.LocalAddress = "0.0.0.0";
@@ -345,6 +369,8 @@ namespace Netch.Forms
return;
}
Global.Settings.ACL = AclAddr.Text;
Global.Settings.TUNTAP.Address = TUNTAPAddressTextBox.Text;
Global.Settings.TUNTAP.Netmask = TUNTAPNetmaskTextBox.Text;
Global.Settings.TUNTAP.Gateway = TUNTAPGatewayTextBox.Text;

View File

@@ -88,7 +88,7 @@
this.UserAgentLabel.AutoSize = true;
this.UserAgentLabel.Location = new System.Drawing.Point(11, 77);
this.UserAgentLabel.Name = "UserAgentLabel";
this.UserAgentLabel.Size = new System.Drawing.Size(73, 17);
this.UserAgentLabel.Size = new System.Drawing.Size(74, 17);
this.UserAgentLabel.TabIndex = 5;
this.UserAgentLabel.Text = "User-Agent";
//
@@ -150,6 +150,7 @@
this.SubscribeLinkListView.TabIndex = 0;
this.SubscribeLinkListView.UseCompatibleStateImageBehavior = false;
this.SubscribeLinkListView.View = System.Windows.Forms.View.Details;
this.SubscribeLinkListView.SelectedIndexChanged += new System.EventHandler(this.SubscribeLinkListView_SelectedIndexChanged);
//
// RemarkColumnHeader
//
@@ -169,23 +170,22 @@
// pContextMenuStrip
//
this.pContextMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.DeleteToolStripMenuItem});
this.pContextMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.DeleteToolStripMenuItem,
this.CopyLinkToolStripMenuItem});
this.pContextMenuStrip.Name = "pContextMenuStrip";
this.pContextMenuStrip.Size = new System.Drawing.Size(114, 26);
this.pContextMenuStrip.Size = new System.Drawing.Size(130, 48);
//
// DeleteToolStripMenuItem
//
this.DeleteToolStripMenuItem.Name = "DeleteToolStripMenuItem";
this.DeleteToolStripMenuItem.Size = new System.Drawing.Size(113, 22);
this.DeleteToolStripMenuItem.Size = new System.Drawing.Size(129, 22);
this.DeleteToolStripMenuItem.Text = "Delete";
this.DeleteToolStripMenuItem.Click += new System.EventHandler(this.DeleteToolStripMenuItem_Click);
//
// CopyLinkToolStripMenuItem
//
this.CopyLinkToolStripMenuItem.Name = "CopyLinkToolStripMenuItem";
this.CopyLinkToolStripMenuItem.Size = new System.Drawing.Size(113, 22);
this.CopyLinkToolStripMenuItem.Size = new System.Drawing.Size(129, 22);
this.CopyLinkToolStripMenuItem.Text = "CopyLink";
this.CopyLinkToolStripMenuItem.Click += new System.EventHandler(this.CopyLinkToolStripMenuItem_Click);
//

View File

@@ -1,5 +1,4 @@
using Netch.Models;
using System;
using System;
using System.Collections.Generic;
using System.Windows.Forms;
@@ -144,5 +143,15 @@ namespace Netch.Forms
MessageBox.Show(Utils.i18N.Translate("Successfully saved"), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
Close();
}
/// <summary>
/// 订阅列表选中节点
/// TODO 选中节点编辑
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void SubscribeLinkListView_SelectedIndexChanged(object sender, EventArgs e)
{
//MessageBox.Show(SubscribeLinkListView.SelectedItems + "", Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}

View File

@@ -1,7 +1,7 @@
namespace Netch.Models
{
public class Profile
{
{
public string ServerRemark;
public string ModeRemark;
public string ProfileName;
@@ -24,5 +24,5 @@
}
}
}
}

View File

@@ -102,7 +102,7 @@ namespace Netch.Models
/// <summary>
/// Redirector TCP 占用端口
/// </summary>
//public int RedirectorTCPPort = 2800;
public int RedirectorTCPPort = 3901;
/// <summary>
/// HTTP 和 Socks5 本地代理地址
@@ -173,5 +173,11 @@ namespace Netch.Models
/// 启动后延迟测试间隔/秒
/// </summary>
public int StartedTcping_Interval = 3;
/// <summary>
/// ACL规则
/// </summary>
public string ACL = "https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/banAD.acl";
}
}

View File

@@ -65,8 +65,6 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="DNS" Version="5.0.0" />
<PackageReference Include="DnsClient" Version="1.2.0" />
<PackageReference Include="ini-parser" Version="2.5.2" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="System.Buffers" Version="4.5.0" />
@@ -112,4 +110,5 @@
<Target Condition="'$(VisualStudioDir)' != ''" Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="@ECHO OFF&#xD;&#xA;RD /S /Q $(TargetDir)bin &gt; NUL 2&gt;&amp;1&#xD;&#xA;RD /S /Q $(TargetDir)i18n &gt; NUL 2&gt;&amp;1&#xD;&#xA;RD /S /Q $(TargetDir)mode &gt; NUL 2&gt;&amp;1&#xD;&#xA;&#xD;&#xA;MKDIR $(TargetDir)bin &gt; NUL 2&gt;&amp;1&#xD;&#xA;MKDIR $(TargetDir)i18n &gt; NUL 2&gt;&amp;1&#xD;&#xA;MKDIR $(TargetDir)mode &gt; NUL 2&gt;&amp;1&#xD;&#xA;&#xD;&#xA;COPY /Y $(SolutionDir)binaries\$(PlatformName)\* $(TargetDir)bin &gt; NUL 2&gt;&amp;1&#xD;&#xA;COPY /Y $(SolutionDir)binaries\* $(TargetDir)bin &gt; NUL 2&gt;&amp;1&#xD;&#xA;MOVE /Y $(TargetDir)bin\nfapinet.dll $(TargetDir)nfapinet.dll &gt; NUL 2&gt;&amp;1&#xD;&#xA;COPY /Y $(SolutionDir)translations\i18n\* $(TargetDir)i18n &gt; NUL 2&gt;&amp;1&#xD;&#xA;COPY /Y $(SolutionDir)modes\mode\*.txt $(TargetDir)mode &gt; NUL 2&gt;&amp;1&#xD;&#xA;MKDIR $(TargetDir)bin\tap-driver &gt; NUL 2&gt;&amp;1&#xD;&#xA;COPY /Y $(SolutionDir)binaries\$(PlatformName)\tap-driver\* $(TargetDir)bin\tap-driver &gt; NUL 2&gt;&amp;1" />
</Target>
<ProjectExtensions><VisualStudio><UserProperties /></VisualStudio></ProjectExtensions>
</Project>

View File

@@ -8,8 +8,8 @@ namespace Netch.Override
protected override WebRequest GetWebRequest(Uri address)
{
var request = base.GetWebRequest(address);
request.Timeout = 4000;
((HttpWebRequest)request).ReadWriteTimeout = 4000;
request.Timeout = 10000;
((HttpWebRequest)request).ReadWriteTimeout = 10000;
return request;
}

View File

@@ -1,6 +1,6 @@
using System.Reflection;
using Netch.Controllers;
using System.Reflection;
using System.Runtime.InteropServices;
using Netch.Controllers;
// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改

View File

@@ -1,59 +0,0 @@
using DNS.Protocol;
using System;
using System.Linq;
using System.Threading.Tasks;
namespace Netch
{
public class Resolver : DNS.Client.RequestResolver.IRequestResolver
{
public Task<IResponse> Resolve(IRequest request)
{
IResponse response = Response.FromRequest(request);
foreach (var question in response.Questions)
{
if (question.Type == RecordType.A)
{
var client = new DnsClient.LookupClient(DnsClient.NameServer.GooglePublicDns);
client.UseTcpOnly = true;
client.UseCache = true;
try
{
var result = client.Query(question.Name.ToString(), DnsClient.QueryType.A);
foreach (var item in result.Answers.ARecords())
{
response.AnswerRecords.Add(new DNS.Protocol.ResourceRecords.IPAddressResourceRecord(question.Name, item.Address));
}
}
catch (Exception)
{
// 跳过
}
}
else if (question.Type == RecordType.AAAA)
{
var client = new DnsClient.LookupClient(DnsClient.NameServer.GooglePublicDns);
client.UseTcpOnly = true;
client.UseCache = true;
try
{
var result = client.Query(question.Name.ToString(), DnsClient.QueryType.AAAA);
foreach (var item in result.Answers.AaaaRecords())
{
response.AnswerRecords.Add(new DNS.Protocol.ResourceRecords.IPAddressResourceRecord(question.Name, item.Address));
}
}
catch (Exception)
{
// 跳过
}
}
}
return Task.FromResult(response);
}
}
}

View File

@@ -23,8 +23,9 @@
"Starting NatTester": "正在启动Nat测试",
"Starting LocalDns service": "正在启动本地DNS服务",
"Starting Redirector": "正在启动Redirector",
"ReStarting Redirector": "正常启动失败正在尝试重新启动Redirector",
"Starting netfilter2 Service": "正在启动netfilter2服务",
"Starting dns2tcp Service": "正在启动dns2tcp服务",
"Starting dns Service": "正在启动dns服务",
"SetupBypass": "设置绕行规则",
"Test failed": "测试失败",
"Starting update subscription": "正在更新订阅",
@@ -87,6 +88,9 @@
"Modes have been reload": "模式已重载",
"Clean DNS Cache": "清理 DNS 缓存",
"DNS cache cleanup succeeded": "DNS 缓存清理成功",
"Update ACL": "更新ACL规则",
"ACL updated successfully": "ACL更新成功",
"ACL update failed": "ACL更新失败",
"About": "关于",
"Telegram Channel": "Telegram 频道",
@@ -157,6 +161,7 @@
"Delay test after startup": "启动后延迟测试",
"Enable": "启用",
"Detection interval(/s)": "检测间隔(/秒)",
"Custom ACL": "自定义ACL规则",
"Profile": "配置名",
"Profiles": "配置",

View File

@@ -4,6 +4,7 @@ using System.IO;
using System.Net;
using System.Net.NetworkInformation;
using System.Net.Sockets;
using System.Threading;
using System.Windows.Forms;
namespace Netch.Utils
@@ -169,10 +170,13 @@ namespace Netch.Utils
installProcess.Start();
installProcess.WaitForExit();
installProcess.Close();
//给点时间不然立马安装完毕就查找适配器可能会导致找不到适配器ID
Thread.Sleep(1000);
Global.TUNTAP.ComponentID = TUNTAP.GetComponentID();
}
else {
else
{
return false;
}
//MessageBox.Show(i18N.Translate("Please install TAP-Windows and create an TUN/TAP adapter manually"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);

View File

@@ -1,12 +1,12 @@
using System;
using Netch.Models;
using Netch.Models.SS;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Web;
using Netch.Models;
using Netch.Models.SS;
using Newtonsoft.Json;
namespace Netch.Utils
{
@@ -290,80 +290,88 @@ namespace Netch.Utils
}
else if (text.StartsWith("ssr://"))
{
var data = new Server();
data.Type = "SSR";
text = text.Substring(6);
list.Add(SsrServerFromLink(text));
var parser = new Regex(@"^(?<server>.+):(?<port>(-?\d+?)):(?<protocol>.+?):(?<method>.+?):(?<obfs>.+?):(?<password>.+?)/\?(?<info>.*)$");
var match = parser.Match(URLSafeBase64Decode(text));
/* var data = new Server();
data.Type = "SSR";
if (match.Success)
{
data.Hostname = match.Groups["server"].Value;
data.Port = int.Parse(match.Groups["port"].Value);
if (data.Port < 0)
{
data.Port += 65536;
}
data.Password = URLSafeBase64Decode(match.Groups["password"].Value);
text = text.Substring(6);
data.EncryptMethod = match.Groups["method"].Value;
if (!Global.EncryptMethods.SSR.Contains(data.EncryptMethod))
{
Logging.Info(string.Format("不支持的 SSR 加密方式:{0}", data.EncryptMethod));
return null;
}
var parser = new Regex(@"^(?<server>.+):(?<port>(-?\d+?)):(?<protocol>.+?):(?<method>.+?):(?<obfs>.+?):(?<password>.+?)/\?(?<info>.*)$");
var parser2 = new Regex(@"^(?<server>.+):(?<port>(-?\d+?)):(?<protocol>.+?):(?<method>.+?):(?<obfs>.+?):(?<password>.+?)/$");
var match = parser2.Match(URLSafeBase64Decode(text));
if (!match.Success)
{
match = parser2.Match(UnBase64String(text));
}
data.Protocol = match.Groups["protocol"].Value;
if (!Global.Protocols.Contains(data.Protocol))
{
Logging.Info(string.Format("不支持的 SSR 协议:{0}", data.Protocol));
return null;
}
if (match.Success)
{
data.Hostname = match.Groups["server"].Value;
data.Port = int.Parse(match.Groups["port"].Value);
if (data.Port < 0)
{
data.Port += 65536;
}
data.Password = URLSafeBase64Decode(match.Groups["password"].Value);
data.OBFS = match.Groups["obfs"].Value;
if (data.OBFS == @"tls1.2_ticket_fastauth")
{
data.OBFS = @"tls1.2_ticket_auth";
}
if (!Global.OBFSs.Contains(data.OBFS))
{
Logging.Info(string.Format("不支持的 SSR 混淆:{0}", data.OBFS));
return null;
}
data.EncryptMethod = match.Groups["method"].Value;
if (!Global.EncryptMethods.SSR.Contains(data.EncryptMethod))
{
Logging.Info(string.Format("不支持的 SSR 加密方式:{0}", data.EncryptMethod));
return null;
}
var info = match.Groups["info"].Value;
var dict = new Dictionary<string, string>();
foreach (var str in info.Split('&'))
{
var splited = str.Split('=');
dict.Add(splited[0], splited[1]);
}
data.Protocol = match.Groups["protocol"].Value;
if (!Global.Protocols.Contains(data.Protocol))
{
Logging.Info(string.Format("不支持的 SSR 协议:{0}", data.Protocol));
return null;
}
if (dict.ContainsKey("remarks"))
{
data.Remark = URLSafeBase64Decode(dict["remarks"]);
}
data.OBFS = match.Groups["obfs"].Value;
if (data.OBFS == @"tls1.2_ticket_fastauth")
{
data.OBFS = @"tls1.2_ticket_auth";
}
if (!Global.OBFSs.Contains(data.OBFS))
{
Logging.Info(string.Format("不支持的 SSR 混淆:{0}", data.OBFS));
return null;
}
if (dict.ContainsKey("protoparam"))
{
data.ProtocolParam = URLSafeBase64Decode(dict["protoparam"]);
}
var info = match.Groups["info"].Value;
var dict = new Dictionary<string, string>();
foreach (var str in info.Split('&'))
{
var splited = str.Split('=');
dict.Add(splited[0], splited[1]);
}
if (dict.ContainsKey("obfsparam"))
{
data.OBFSParam = URLSafeBase64Decode(dict["obfsparam"]);
}
if (dict.ContainsKey("remarks"))
{
data.Remark = URLSafeBase64Decode(dict["remarks"]);
}
if (Global.EncryptMethods.SS.Contains(data.EncryptMethod) && data.Protocol == "origin" && data.OBFS == "plain")
{
data.OBFS = "";
data.Type = "SS";
}
}
if (dict.ContainsKey("protoparam"))
{
data.ProtocolParam = URLSafeBase64Decode(dict["protoparam"]);
}
if (dict.ContainsKey("obfsparam"))
{
data.OBFSParam = URLSafeBase64Decode(dict["obfsparam"]);
}
if (Global.EncryptMethods.SS.Contains(data.EncryptMethod) && data.Protocol == "origin" && data.OBFS == "plain")
{
data.OBFS = "";
data.Type = "SS";
}
list.Add(data);
}*/
list.Add(data);
}
else if (text.StartsWith("vmess://"))
{
@@ -517,5 +525,123 @@ namespace Netch.Utils
return list;
}
public static string UnBase64String(string value)
{
if (value == null || value == "")
{
return "";
}
byte[] bytes = Convert.FromBase64String(value);
return Encoding.UTF8.GetString(bytes);
}
public static string ToBase64String(string value)
{
if (value == null || value == "")
{
return "";
}
byte[] bytes = Encoding.UTF8.GetBytes(value);
return Convert.ToBase64String(bytes);
}
/// <summary>
/// SSR链接解析器
/// Copy From https://github.com/HMBSbige/ShadowsocksR-Windows/blob/d9dc8d032a6e04c14b9dc6c8f673c9cc5aa9f607/shadowsocks-csharp/Model/Server.cs#L428
/// Thx :D
/// </summary>
/// <param name="ssrUrl"></param>
/// <returns></returns>
public static Server SsrServerFromLink(string ssrUrl)
{
// ssr://host:port:protocol:method:obfs:base64pass/?obfsparam=base64&remarks=base64&group=base64&udpport=0&uot=1
var ssr = Regex.Match(ssrUrl, "ssr://([A-Za-z0-9_-]+)", RegexOptions.IgnoreCase);
if (!ssr.Success)
throw new FormatException();
var data = URLSafeBase64Decode(ssr.Groups[1].Value);
var params_dict = new Dictionary<string, string>();
var param_start_pos = data.IndexOf("?", StringComparison.Ordinal);
if (param_start_pos > 0)
{
params_dict = ParseParam(data.Substring(param_start_pos + 1));
data = data.Substring(0, param_start_pos);
}
if (data.IndexOf("/", StringComparison.Ordinal) >= 0)
{
data = data.Substring(0, data.LastIndexOf("/", StringComparison.Ordinal));
}
var UrlFinder = new Regex("^(.+):([^:]+):([^:]*):([^:]+):([^:]*):([^:]+)");
var match = UrlFinder.Match(data);
if (match == null || !match.Success)
throw new FormatException();
var serverAddr = match.Groups[1].Value;
var Server_Port = ushort.Parse(match.Groups[2].Value);
var Protocol = match.Groups[3].Value.Length == 0 ? "origin" : match.Groups[3].Value;
Protocol = Protocol.Replace("_compatible", "");
var Method = match.Groups[4].Value;
var obfs = match.Groups[5].Value.Length == 0 ? "plain" : match.Groups[5].Value;
obfs = obfs.Replace("_compatible", "");
var Password = URLSafeBase64Decode(match.Groups[6].Value);
var ProtocolParam = "";
var ObfsParam = "";
var Remarks = "";
var Group = "";
if (params_dict.ContainsKey("protoparam"))
{
ProtocolParam = URLSafeBase64Decode(params_dict["protoparam"]);
}
if (params_dict.ContainsKey("obfsparam"))
{
ObfsParam = URLSafeBase64Decode(params_dict["obfsparam"]);
}
if (params_dict.ContainsKey("remarks"))
{
Remarks = URLSafeBase64Decode(params_dict["remarks"]);
}
Group = params_dict.ContainsKey("group") ? URLSafeBase64Decode(params_dict["group"]) : string.Empty;
/*if (params_dict.ContainsKey("uot"))
{
UdpOverTcp = int.Parse(params_dict["uot"]) != 0;
}
if (params_dict.ContainsKey("udpport"))
{
Server_Udp_Port = ushort.Parse(params_dict["udpport"]);
}*/
Server server = new Server();
server.Type = "SSR";
server.Hostname = serverAddr;
server.Port = Server_Port;
server.Protocol = Protocol;
server.EncryptMethod = Method;
server.OBFS = obfs;
server.Password = Password;
server.ProtocolParam = ProtocolParam;
server.OBFSParam = ObfsParam;
server.Remark = Remarks;
server.Group = Group;
return server;
}
private static Dictionary<string, string> ParseParam(string paramStr)
{
var paramsDict = new Dictionary<string, string>();
var obfsParams = paramStr.Split('&');
foreach (var p in obfsParams)
{
if (p.IndexOf('=') > 0)
{
var index = p.IndexOf('=');
var key = p.Substring(0, index);
var val = p.Substring(index + 1);
paramsDict[key] = val;
}
}
return paramsDict;
}
}
}

2
modes

Submodule modes updated: 0062332e64...a9329cd3f1