From 00903d35310c6cdfc4f9eede5ec59b843b3ea71a Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Fri, 19 Jun 2026 18:09:18 +0800 Subject: [PATCH] Verify if sendThrough is a local address. https://github.com/2dust/v2rayN/issues/9562 --- v2rayN/ServiceLib/Common/Utils.cs | 12 ++++++++++++ .../Singbox/SingboxConfigTemplateService.cs | 5 +++++ .../CoreConfig/V2ray/V2rayConfigTemplateService.cs | 5 +++++ 3 files changed, 22 insertions(+) diff --git a/v2rayN/ServiceLib/Common/Utils.cs b/v2rayN/ServiceLib/Common/Utils.cs index 87e0833d..b6831dff 100644 --- a/v2rayN/ServiceLib/Common/Utils.cs +++ b/v2rayN/ServiceLib/Common/Utils.cs @@ -716,6 +716,18 @@ public class Utils return (endpoints, connections); } + public static bool IsLocalIP(string ipAddress) + { + if (!IPAddress.TryParse(ipAddress, out var targetAddress)) + { + return false; + } + + return NetworkInterface.GetAllNetworkInterfaces() + .SelectMany(ni => ni.GetIPProperties().UnicastAddresses) + .Any(ua => ua.Address.Equals(targetAddress)); + } + #endregion Speed Test #region Miscellaneous diff --git a/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxConfigTemplateService.cs b/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxConfigTemplateService.cs index 8e573a21..171c2ecd 100644 --- a/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxConfigTemplateService.cs +++ b/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxConfigTemplateService.cs @@ -83,6 +83,11 @@ public partial class CoreConfigSingboxService { return; } + if (!Utils.IsLocalIP(sendThrough)) + { + return; + } + foreach (var outbound in _coreConfig.outbounds ?? []) { outbound.inet4_bind_address = ShouldBindNet(outbound) ? sendThrough : null; diff --git a/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayConfigTemplateService.cs b/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayConfigTemplateService.cs index d7a6a9b5..6bc7079a 100644 --- a/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayConfigTemplateService.cs +++ b/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayConfigTemplateService.cs @@ -176,6 +176,11 @@ public partial class CoreConfigV2rayService { return; } + if (!Utils.IsLocalIP(sendThrough)) + { + return; + } + foreach (var outbound in _coreConfig.outbounds ?? []) { outbound.sendThrough = ShouldBindNet(outbound) ? sendThrough : null;