This commit is contained in:
snltty
2026-04-03 15:59:19 +08:00
parent e710439beb
commit d70fd7fb40
3 changed files with 40 additions and 6 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
v1.9.96
2026-04-03 15:13:42
2026-04-03 15:59:19
1. 一些累计更新,一些BUG修复
2. #92 松开打洞loading限制,允许选择中继节点
3. #89 windows下利用任务计划进行进程守护,定时检查服务
+35 -4
View File
@@ -1,11 +1,20 @@
using System;
using System.IO;
using System.Linq;
using System.Net;
using System.Xml.Linq;
namespace linker.libs
{
public static class FireWallHelper
{
public static void Write(string fileName)
{
if (OperatingSystem.IsWindows())
{
Windows(fileName);
}
}
public static void Write(string fileName, IPAddress ip, byte prefixLength)
{
if (OperatingSystem.IsWindows())
@@ -13,11 +22,11 @@ namespace linker.libs
Windows(fileName, ip, prefixLength);
}
}
public static void Write(string fileName)
public static void Write(string fileName, (IPAddress ip, IPAddress mapIp, byte prefixLength)[] lans)
{
if (OperatingSystem.IsWindows())
{
Windows(fileName);
Windows(fileName, lans);
}
}
private static void Windows(string fileName)
@@ -27,7 +36,10 @@ namespace linker.libs
string name = Path.GetFileNameWithoutExtension(fileName);
CommandHelper.Windows(string.Empty, new string[] {
$"netsh advfirewall firewall delete rule name=\"{name}-any\"",
$"netsh advfirewall firewall add rule name=\"{name}-any\" dir=in action=allow program=\"{fileName}\" enable=yes"
$"netsh advfirewall firewall delete rule name=\"{name}-tcp\"",
$"netsh advfirewall firewall add rule name=\"{name}-tcp\" dir=in action=allow protocol=tcp program=\"{fileName}\" enable=yes",
$"netsh advfirewall firewall delete rule name=\"{name}-udp\"",
$"netsh advfirewall firewall add rule name=\"{name}-udp\" dir=in action=allow protocol=udp program=\"{fileName}\" enable=yes"
});
}
catch (Exception)
@@ -41,7 +53,10 @@ namespace linker.libs
string name = Path.GetFileNameWithoutExtension(fileName);
CommandHelper.Windows(string.Empty, new string[] {
$"netsh advfirewall firewall delete rule name=\"{name}-any\"",
$"netsh advfirewall firewall add rule name=\"{name}-any\" dir=in action=allow program=\"{fileName}\" enable=yes",
$"netsh advfirewall firewall delete rule name=\"{name}-tcp\"",
$"netsh advfirewall firewall add rule name=\"{name}-tcp\" dir=in action=allow protocol=tcp program=\"{fileName}\" enable=yes",
$"netsh advfirewall firewall delete rule name=\"{name}-udp\"",
$"netsh advfirewall firewall add rule name=\"{name}-udp\" dir=in action=allow protocol=udp program=\"{fileName}\" enable=yes",
$"netsh advfirewall firewall delete rule name=\"{name}-icmp\"",
$"netsh advfirewall firewall add rule name=\"{name}-icmp\" dir=in action=allow protocol=icmpv4 localip={ip}/{prefixLength} enable=yes",
});
@@ -50,5 +65,21 @@ namespace linker.libs
{
}
}
private static void Windows(string fileName, (IPAddress ip, IPAddress mapIp, byte prefixLength)[] lans)
{
try
{
string name = Path.GetFileNameWithoutExtension(fileName);
string str = CommandHelper.Windows(string.Empty, [$"netsh advfirewall firewall show rule name=all | findstr \"{name}-icmp-\""]);
string[] delete = str.Split('\n').Where(c=>c.Contains($"{name}-icmp-")).Select(c => c.Split($"{name}-icmp-")).Select(c => $"netsh advfirewall firewall delete rule name=\"{name}-icmp-{c[1]}\"").ToArray();
CommandHelper.Windows(string.Empty, delete);
string[] add = lans.Select(c => $"netsh advfirewall firewall add rule name=\"{name}-icmp-{Environment.TickCount64}\" dir=in action=allow protocol=icmpv4 localip={(IPAddress.Any.Equals(c.mapIp) ? c.ip : c.mapIp)}/{c.prefixLength} enable=yes").ToArray();
CommandHelper.Windows(string.Empty, add);
}
catch (Exception)
{
}
}
}
}
@@ -78,7 +78,10 @@ namespace linker.messenger.tuntap.client
SetNat();
SetMaps();
AddForward();
FireWallHelper.Write(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName, tuntapConfigTransfer.Info.IP, tuntapConfigTransfer.PrefixLength);
string fileName = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
FireWallHelper.Write(fileName, tuntapConfigTransfer.Info.IP, tuntapConfigTransfer.PrefixLength);
FireWallHelper.Write(fileName,tuntapConfigTransfer.Info.Lans.Where(c => c.IP != null && c.IP.Equals(IPAddress.Any) == false).Select(c => (c.IP,c.MapIP, c.PrefixLength)).ToArray());
}
private void ShutdownBefore()
{