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;