This commit is contained in:
snltty
2026-04-03 16:06:11 +08:00
parent d70fd7fb40
commit 0cd105d579
3 changed files with 8 additions and 29 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
v1.9.96
2026-04-03 15:59:19
2026-04-03 16:06:11
1. 一些累计更新,一些BUG修复
2. #92 松开打洞loading限制,允许选择中继节点
3. #89 windows下利用任务计划进行进程守护,定时检查服务
+6 -25
View File
@@ -15,18 +15,11 @@ namespace linker.libs
Windows(fileName);
}
}
public static void Write(string fileName, IPAddress ip, byte prefixLength)
public static void Write(string fileName, IPAddress ip, byte prefixLength, (IPAddress ip, IPAddress mapIp, byte prefixLength)[] lans)
{
if (OperatingSystem.IsWindows())
{
Windows(fileName, ip, prefixLength);
}
}
public static void Write(string fileName, (IPAddress ip, IPAddress mapIp, byte prefixLength)[] lans)
{
if (OperatingSystem.IsWindows())
{
Windows(fileName, lans);
Windows(fileName, ip, prefixLength, lans);
}
}
private static void Windows(string fileName)
@@ -35,6 +28,7 @@ namespace linker.libs
{
string name = Path.GetFileNameWithoutExtension(fileName);
CommandHelper.Windows(string.Empty, new string[] {
$"netsh advfirewall firewall delete rule name=\"{name}\"",
$"netsh advfirewall firewall delete rule name=\"{name}-any\"",
$"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",
@@ -46,12 +40,13 @@ namespace linker.libs
{
}
}
private static void Windows(string fileName, IPAddress ip, byte prefixLength)
private static void Windows(string fileName, IPAddress ip, byte prefixLength, (IPAddress ip, IPAddress mapIp, byte prefixLength)[] lans)
{
try
{
string name = Path.GetFileNameWithoutExtension(fileName);
CommandHelper.Windows(string.Empty, new string[] {
$"netsh advfirewall firewall delete rule name=\"{name}\"",
$"netsh advfirewall firewall delete rule name=\"{name}-any\"",
$"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",
@@ -60,21 +55,7 @@ namespace linker.libs
$"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",
});
}
catch (Exception)
{
}
}
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();
string[] add = lans.Select(c => $"netsh advfirewall firewall add rule name=\"{name}-icmp\" 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)
@@ -79,9 +79,7 @@ namespace linker.messenger.tuntap.client
SetMaps();
AddForward();
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());
FireWallHelper.Write(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName, tuntapConfigTransfer.Info.IP, tuntapConfigTransfer.PrefixLength, 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()
{