mirror of
https://github.com/netchx/netch.git
synced 2026-05-11 23:45:06 +08:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
84b412bc8c | ||
|
|
7fef3dfe5c | ||
|
|
c139a82bdf | ||
|
|
97f6d601fb | ||
|
|
1ea0bb4096 | ||
|
|
7265bd2922 | ||
|
|
f316e13ada |
@@ -166,6 +166,7 @@ namespace Netch.Controllers
|
|||||||
return;
|
return;
|
||||||
case State.Stopped:
|
case State.Stopped:
|
||||||
Stop();
|
Stop();
|
||||||
|
CloseLogFile();
|
||||||
OnKeywordStopped();
|
OnKeywordStopped();
|
||||||
throw new MessageException($"{Name} 控制器启动失败");
|
throw new MessageException($"{Name} 控制器启动失败");
|
||||||
}
|
}
|
||||||
@@ -180,6 +181,9 @@ namespace Netch.Controllers
|
|||||||
|
|
||||||
private void OpenLogFile()
|
private void OpenLogFile()
|
||||||
{
|
{
|
||||||
|
if (!RedirectToFile)
|
||||||
|
return;
|
||||||
|
|
||||||
_logFileStream = File.Open(LogPath, FileMode.Create, FileAccess.ReadWrite, FileShare.Read);
|
_logFileStream = File.Open(LogPath, FileMode.Create, FileAccess.ReadWrite, FileShare.Read);
|
||||||
_logStreamWriter = new StreamWriter(_logFileStream);
|
_logStreamWriter = new StreamWriter(_logFileStream);
|
||||||
|
|
||||||
@@ -201,8 +205,8 @@ namespace Netch.Controllers
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
_flushFileStreamTimer.Enabled = false;
|
_flushFileStreamTimer.Enabled = false;
|
||||||
_logStreamWriter!.Close();
|
_logStreamWriter?.Close();
|
||||||
_logFileStream!.Close();
|
_logFileStream?.Close();
|
||||||
_logStreamWriter = _logStreamWriter = null;
|
_logStreamWriter = _logStreamWriter = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -234,8 +238,8 @@ namespace Netch.Controllers
|
|||||||
string? line;
|
string? line;
|
||||||
while ((line = reader.ReadLine()) != null)
|
while ((line = reader.ReadLine()) != null)
|
||||||
{
|
{
|
||||||
OnReadNewLine(line);
|
|
||||||
WriteLog(line);
|
WriteLog(line);
|
||||||
|
OnReadNewLine(line);
|
||||||
|
|
||||||
// State == State.Started if !StartedKeywords.Any()
|
// State == State.Started if !StartedKeywords.Any()
|
||||||
if (State == State.Starting)
|
if (State == State.Starting)
|
||||||
@@ -247,8 +251,8 @@ namespace Netch.Controllers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
State = State.Stopped;
|
|
||||||
CloseLogFile();
|
CloseLogFile();
|
||||||
|
State = State.Stopped;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ using System.Threading;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Netch.Forms;
|
using Netch.Forms;
|
||||||
using Netch.Models;
|
using Netch.Models;
|
||||||
|
using Netch.Servers.Socks5;
|
||||||
|
|
||||||
namespace Netch.Controllers
|
namespace Netch.Controllers
|
||||||
{
|
{
|
||||||
@@ -22,31 +23,37 @@ namespace Netch.Controllers
|
|||||||
|
|
||||||
protected override Encoding? InstanceOutputEncoding { get; } = Encoding.UTF8;
|
protected override Encoding? InstanceOutputEncoding { get; } = Encoding.UTF8;
|
||||||
|
|
||||||
public PcapController()
|
|
||||||
{
|
|
||||||
RedirectToFile = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private LogForm? _form;
|
private LogForm? _form;
|
||||||
|
|
||||||
public void Start(in Mode mode)
|
public void Start(in Mode mode)
|
||||||
{
|
{
|
||||||
Global.MainForm.BeginInvoke(new Action(() =>
|
var server = MainController.Server!;
|
||||||
{
|
|
||||||
_form = new LogForm(Global.MainForm);
|
|
||||||
_form.Show();
|
|
||||||
}));
|
|
||||||
|
|
||||||
StartInstanceAuto($@"-i \Device\NPF_{_outbound.NetworkInterface.Id} {mode.FullRule.FirstOrDefault() ?? "-P n"}");
|
_form = new LogForm(Global.MainForm);
|
||||||
|
_form.CreateControl();
|
||||||
|
|
||||||
|
var argument = new StringBuilder($@"-i \Device\NPF_{_outbound.NetworkInterface.Id}");
|
||||||
|
if (server is Socks5 socks5 && !socks5.Auth())
|
||||||
|
argument.Append($" --destination {server.AutoResolveHostname()}:{server.Port}");
|
||||||
|
else
|
||||||
|
argument.Append($" --destination 127.0.0.1:{Global.Settings.Socks5LocalPort}");
|
||||||
|
|
||||||
|
argument.Append($" {mode.FullRule.FirstOrDefault() ?? "-P n"}");
|
||||||
|
StartInstanceAuto(argument.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnReadNewLine(string line)
|
protected override void OnReadNewLine(string line)
|
||||||
{
|
{
|
||||||
Global.MainForm.BeginInvoke(new Action(() => { _form!.richTextBox1.AppendText(line + "\n"); }));
|
Global.MainForm.BeginInvoke(new Action(() =>
|
||||||
|
{
|
||||||
|
if (!_form!.IsDisposed)
|
||||||
|
_form!.richTextBox1.AppendText(line + "\n");
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnKeywordStarted()
|
protected override void OnKeywordStarted()
|
||||||
{
|
{
|
||||||
|
Global.MainForm.BeginInvoke(new Action(() => { _form!.Show(); }));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnKeywordStopped()
|
protected override void OnKeywordStopped()
|
||||||
@@ -67,8 +74,7 @@ namespace Netch.Controllers
|
|||||||
|
|
||||||
public override void Stop()
|
public override void Stop()
|
||||||
{
|
{
|
||||||
Global.MainForm.Invoke(new Action(() => { _form!.Close(); }));
|
_form!.Close();
|
||||||
|
|
||||||
StopInstance();
|
StopInstance();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ namespace Netch.Controllers
|
|||||||
public const string Name = @"Netch";
|
public const string Name = @"Netch";
|
||||||
public const string Copyright = @"Copyright © 2019 - 2021";
|
public const string Copyright = @"Copyright © 2019 - 2021";
|
||||||
|
|
||||||
public const string AssemblyVersion = @"1.8.0";
|
public const string AssemblyVersion = @"1.8.1";
|
||||||
private const string Suffix = @"";
|
private const string Suffix = @"";
|
||||||
|
|
||||||
public static readonly string Version = $"{AssemblyVersion}{(string.IsNullOrEmpty(Suffix) ? "" : $"-{Suffix}")}";
|
public static readonly string Version = $"{AssemblyVersion}{(string.IsNullOrEmpty(Suffix) ? "" : $"-{Suffix}")}";
|
||||||
|
|||||||
@@ -16,9 +16,9 @@ namespace Netch.Forms
|
|||||||
_parent = parent;
|
_parent = parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnShown(EventArgs e)
|
protected override void OnLoad(EventArgs e)
|
||||||
{
|
{
|
||||||
base.OnShown(e);
|
base.OnLoad(e);
|
||||||
Parent_Move(null!, null!);
|
Parent_Move(null!, null!);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ namespace Netch.Servers.Shadowsocks
|
|||||||
|
|
||||||
public IEnumerable<Server> ParseSsdUri(string s)
|
public IEnumerable<Server> ParseSsdUri(string s)
|
||||||
{
|
{
|
||||||
var json = JsonSerializer.Deserialize<Main>(ShareLink.URLSafeBase64Decode(s.Substring(6)));
|
var json = JsonSerializer.Deserialize<Main>(ShareLink.URLSafeBase64Decode(s.Substring(6)))!;
|
||||||
|
|
||||||
return json.servers.Select(server => new Shadowsocks
|
return json.servers.Select(server => new Shadowsocks
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ namespace Netch.Servers.VMess
|
|||||||
|
|
||||||
if (data.TransferProtocol == "quic")
|
if (data.TransferProtocol == "quic")
|
||||||
{
|
{
|
||||||
if (VMessGlobal.QUIC.Contains(vmess.host))
|
if (VMessGlobal.QUIC.Contains(vmess.host!))
|
||||||
{
|
{
|
||||||
data.QUICSecure = vmess.host;
|
data.QUICSecure = vmess.host;
|
||||||
data.QUICSecret = vmess.path;
|
data.QUICSecret = vmess.path;
|
||||||
|
|||||||
@@ -53,8 +53,7 @@ namespace Netch.Utils
|
|||||||
|
|
||||||
#region Check Profile
|
#region Check Profile
|
||||||
|
|
||||||
foreach (var profile in settings.Profiles.Where(p => p.ServerRemark == string.Empty || p.ModeRemark == string.Empty)!)
|
settings.Profiles.RemoveAll(p => p.ServerRemark == string.Empty || p.ModeRemark == string.Empty);
|
||||||
settings.Profiles.Remove(profile);
|
|
||||||
|
|
||||||
if (settings.Profiles.Any(p => settings.Profiles.Any(p1 => p1 != p && p1.Index == p.Index)))
|
if (settings.Profiles.Any(p => settings.Profiles.Any(p1 => p1 != p && p1.Index == p.Index)))
|
||||||
for (var i = 0; i < settings.Profiles.Count; i++)
|
for (var i = 0; i < settings.Profiles.Count; i++)
|
||||||
@@ -67,7 +66,9 @@ namespace Netch.Utils
|
|||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Logging.Error(e.ToString());
|
Logging.Error(e.ToString());
|
||||||
return new Setting();
|
Utils.Open(Logging.LogFile);
|
||||||
|
Environment.Exit(-1);
|
||||||
|
return null!;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -46,8 +46,22 @@ namespace Netch.Utils
|
|||||||
}
|
}
|
||||||
catch (JsonException)
|
catch (JsonException)
|
||||||
{
|
{
|
||||||
|
var errorFlag = false;
|
||||||
foreach (var line in text.GetLines())
|
foreach (var line in text.GetLines())
|
||||||
list.AddRange(ParseUri(line));
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
list.AddRange(ParseUri(line));
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
errorFlag = true;
|
||||||
|
Logging.Error(e.ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (errorFlag)
|
||||||
|
Utils.Open(Logging.LogFile);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
@@ -61,30 +75,22 @@ namespace Netch.Utils
|
|||||||
{
|
{
|
||||||
var list = new List<Server>();
|
var list = new List<Server>();
|
||||||
|
|
||||||
try
|
if (text.StartsWith("tg://socks?") || text.StartsWith("https://t.me/socks?"))
|
||||||
{
|
{
|
||||||
if (text.StartsWith("tg://socks?") || text.StartsWith("https://t.me/socks?"))
|
list.AddRange(ServerHelper.GetUtilByTypeName("Socks5").ParseUri(text));
|
||||||
{
|
|
||||||
list.AddRange(ServerHelper.GetUtilByTypeName("Socks5").ParseUri(text));
|
|
||||||
}
|
|
||||||
else if (text.StartsWith("Netch://"))
|
|
||||||
{
|
|
||||||
list.Add(ParseNetchUri(text));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
var scheme = GetUriScheme(text);
|
|
||||||
var util = ServerHelper.GetUtilByUriScheme(scheme);
|
|
||||||
if (util != null)
|
|
||||||
list.AddRange(util.ParseUri(text));
|
|
||||||
else
|
|
||||||
Logging.Warning($"无法处理 {scheme} 协议订阅链接");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
else if (text.StartsWith("Netch://"))
|
||||||
{
|
{
|
||||||
Logging.Error(e.ToString());
|
list.Add(ParseNetchUri(text));
|
||||||
Utils.Open(Logging.LogFile);
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var scheme = GetUriScheme(text);
|
||||||
|
var util = ServerHelper.GetUtilByUriScheme(scheme);
|
||||||
|
if (util != null)
|
||||||
|
list.AddRange(util.ParseUri(text));
|
||||||
|
else
|
||||||
|
Logging.Warning($"无法处理 {scheme} 协议订阅链接");
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var node in list.Where(node => !node.Remark.IsNullOrWhiteSpace()))
|
foreach (var node in list.Where(node => !node.Remark.IsNullOrWhiteSpace()))
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ namespace Netch.Utils
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
var dictionary = JsonSerializer.Deserialize<Dictionary<string, string>>(text);
|
var dictionary = JsonSerializer.Deserialize<Dictionary<string, string>>(text)!;
|
||||||
|
|
||||||
if (!dictionary.Any())
|
if (!dictionary.Any())
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -67,5 +67,6 @@ As well, Netch avoid the restricted NAT problem caused by SSTap. You can use an
|
|||||||
- [Privoxy](https://www.privoxy.org/)
|
- [Privoxy](https://www.privoxy.org/)
|
||||||
- [NatTypeTester](https://github.com/HMBSbige/NatTypeTester)
|
- [NatTypeTester](https://github.com/HMBSbige/NatTypeTester)
|
||||||
- [NetFilter SDK](https://netfiltersdk.com/)
|
- [NetFilter SDK](https://netfiltersdk.com/)
|
||||||
|
- [pcap2socks](https://github.com/zhxie/pcap2socks)
|
||||||
|
|
||||||
[](https://starchart.cc/NetchX/Netch)
|
[](https://starchart.cc/NetchX/Netch)
|
||||||
|
|||||||
@@ -75,3 +75,4 @@ Netch 支持多种语言,在启动时会根据系统语言选择自身语言
|
|||||||
- [Privoxy](https://www.privoxy.org/)
|
- [Privoxy](https://www.privoxy.org/)
|
||||||
- [NatTypeTester](https://github.com/HMBSbige/NatTypeTester)
|
- [NatTypeTester](https://github.com/HMBSbige/NatTypeTester)
|
||||||
- [NetFilter SDK](https://netfiltersdk.com/)
|
- [NetFilter SDK](https://netfiltersdk.com/)
|
||||||
|
- [pcap2socks](https://github.com/zhxie/pcap2socks)
|
||||||
|
|||||||
2
modes
2
modes
Submodule modes updated: d1eca353a4...dd436b3652
Reference in New Issue
Block a user