diff --git a/v2rayN/ServiceLib/Common/JsonUtils.cs b/v2rayN/ServiceLib/Common/JsonUtils.cs
index 773ba79c..6954e124 100644
--- a/v2rayN/ServiceLib/Common/JsonUtils.cs
+++ b/v2rayN/ServiceLib/Common/JsonUtils.cs
@@ -128,5 +128,8 @@ public class JsonUtils
///
///
///
- public static JsonNode? SerializeToNode(object? obj) => JsonSerializer.SerializeToNode(obj);
+ public static JsonNode? SerializeToNode(object? obj, JsonSerializerOptions? options = null)
+ {
+ return JsonSerializer.SerializeToNode(obj, options);
+ }
}
diff --git a/v2rayN/ServiceLib/Global.cs b/v2rayN/ServiceLib/Global.cs
index a667a335..180bd90c 100644
--- a/v2rayN/ServiceLib/Global.cs
+++ b/v2rayN/ServiceLib/Global.cs
@@ -571,5 +571,13 @@ public class Global
{ "engage.cloudflareclient.com", new List { "162.159.192.1", "2606:4700:d0::a29f:c001" } }
};
+ public static readonly List ExpectedIPs =
+ [
+ "geoip:cn",
+ "geoip:ir",
+ "geoip:ru",
+ ""
+ ];
+
#endregion const
}
diff --git a/v2rayN/ServiceLib/Models/ConfigItems.cs b/v2rayN/ServiceLib/Models/ConfigItems.cs
index 8847782b..ea73ffe2 100644
--- a/v2rayN/ServiceLib/Models/ConfigItems.cs
+++ b/v2rayN/ServiceLib/Models/ConfigItems.cs
@@ -269,4 +269,5 @@ public class DNSItem
public string? SingboxStrategy4Direct { get; set; }
public string? SingboxStrategy4Proxy { get; set; }
public string? Hosts { get; set; }
+ public string? DirectExpectedIPs { get; set; }
}
diff --git a/v2rayN/ServiceLib/Models/V2rayConfig.cs b/v2rayN/ServiceLib/Models/V2rayConfig.cs
index a18c7e34..664ab923 100644
--- a/v2rayN/ServiceLib/Models/V2rayConfig.cs
+++ b/v2rayN/ServiceLib/Models/V2rayConfig.cs
@@ -212,6 +212,8 @@ public class DnsServer4Ray
public string? address { get; set; }
public List? domains { get; set; }
public bool? skipFallback { get; set; }
+ public List? expectedIPs { get; set; }
+ public List? unexpectedIPs { get; set; }
}
public class Routing4Ray
diff --git a/v2rayN/ServiceLib/Resx/ResUI.Designer.cs b/v2rayN/ServiceLib/Resx/ResUI.Designer.cs
index 589ff0a5..152ee845 100644
--- a/v2rayN/ServiceLib/Resx/ResUI.Designer.cs
+++ b/v2rayN/ServiceLib/Resx/ResUI.Designer.cs
@@ -2824,7 +2824,7 @@ namespace ServiceLib.Resx {
}
///
- /// 查找类似 Enable to Override sing-box DoH Resolver 的本地化字符串。
+ /// 查找类似 The sing-box DoH resolution server can be overwritten 的本地化字符串。
///
public static string TbSBDoHOverride {
get {
@@ -3822,6 +3822,24 @@ namespace ServiceLib.Resx {
}
}
+ ///
+ /// 查找类似 Validate Direct Expected IPs 的本地化字符串。
+ ///
+ public static string TbValidateDirectExpectedIPs {
+ get {
+ return ResourceManager.GetString("TbValidateDirectExpectedIPs", resourceCulture);
+ }
+ }
+
+ ///
+ /// 查找类似 After configuration, validates returned IPs, returning only expected IPs 的本地化字符串。
+ ///
+ public static string TbValidateDirectExpectedIPsDesc {
+ get {
+ return ResourceManager.GetString("TbValidateDirectExpectedIPsDesc", resourceCulture);
+ }
+ }
+
///
/// 查找类似 xray Freedom Resolution Strategy 的本地化字符串。
///
diff --git a/v2rayN/ServiceLib/Resx/ResUI.fa-Ir.resx b/v2rayN/ServiceLib/Resx/ResUI.fa-Ir.resx
index 6ebf5697..c2e7676a 100644
--- a/v2rayN/ServiceLib/Resx/ResUI.fa-Ir.resx
+++ b/v2rayN/ServiceLib/Resx/ResUI.fa-Ir.resx
@@ -1429,7 +1429,7 @@
Add Common DNS Hosts
- Enable to Override sing-box DoH Resolver
+ The sing-box DoH resolution server can be overwritten
FakeIP
@@ -1452,4 +1452,10 @@
Advanced DNS Settings
+
+ Validate Direct Expected IPs
+
+
+ After configuration, validates returned IPs, returning only expected IPs
+
\ No newline at end of file
diff --git a/v2rayN/ServiceLib/Resx/ResUI.hu.resx b/v2rayN/ServiceLib/Resx/ResUI.hu.resx
index 44504ffd..e7501327 100644
--- a/v2rayN/ServiceLib/Resx/ResUI.hu.resx
+++ b/v2rayN/ServiceLib/Resx/ResUI.hu.resx
@@ -1429,7 +1429,7 @@
Add Common DNS Hosts
- Enable to Override sing-box DoH Resolver
+ The sing-box DoH resolution server can be overwritten
FakeIP
@@ -1452,4 +1452,10 @@
Advanced DNS Settings
+
+ Validate Direct Expected IPs
+
+
+ After configuration, validates returned IPs, returning only expected IPs
+
\ No newline at end of file
diff --git a/v2rayN/ServiceLib/Resx/ResUI.resx b/v2rayN/ServiceLib/Resx/ResUI.resx
index 54a24060..7b111eef 100644
--- a/v2rayN/ServiceLib/Resx/ResUI.resx
+++ b/v2rayN/ServiceLib/Resx/ResUI.resx
@@ -1429,7 +1429,7 @@
Add Common DNS Hosts
- Enable to Override sing-box DoH Resolver
+ The sing-box DoH resolution server can be overwritten
FakeIP
@@ -1452,4 +1452,10 @@
Advanced DNS Settings
+
+ Validate Direct Expected IPs
+
+
+ After configuration, validates returned IPs, returning only expected IPs
+
\ No newline at end of file
diff --git a/v2rayN/ServiceLib/Resx/ResUI.ru.resx b/v2rayN/ServiceLib/Resx/ResUI.ru.resx
index 1eb7ed28..41f9e6ba 100644
--- a/v2rayN/ServiceLib/Resx/ResUI.ru.resx
+++ b/v2rayN/ServiceLib/Resx/ResUI.ru.resx
@@ -1429,7 +1429,7 @@
Add Common DNS Hosts
- Enable to Override sing-box DoH Resolver
+ The sing-box DoH resolution server can be overwritten
FakeIP
@@ -1452,4 +1452,10 @@
Advanced DNS Settings
+
+ Validate Direct Expected IPs
+
+
+ After configuration, validates returned IPs, returning only expected IPs
+
\ No newline at end of file
diff --git a/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx b/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx
index 04d0b16f..3b3a5796 100644
--- a/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx
+++ b/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx
@@ -1449,4 +1449,10 @@
DNS 进阶设置
+
+ 校验直连期望 IP
+
+
+ 配置后,会对返回的 IP 的进行校验,只返回期望 IP
+
\ No newline at end of file
diff --git a/v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx b/v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx
index 5a9e9a02..5d2a2413 100644
--- a/v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx
+++ b/v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx
@@ -1426,7 +1426,7 @@
Add Common DNS Hosts
- Enable to Override sing-box DoH Resolver
+ The sing-box DoH resolution server can be overwritten
FakeIP
@@ -1449,4 +1449,10 @@
Advanced DNS Settings
+
+ Validate Direct Expected IPs
+
+
+ After configuration, validates returned IPs, returning only expected IPs
+
\ No newline at end of file
diff --git a/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigSingboxService.cs b/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigSingboxService.cs
index 993d8ad8..0de63bca 100644
--- a/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigSingboxService.cs
+++ b/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigSingboxService.cs
@@ -1758,6 +1758,10 @@ public class CoreConfigSingboxService
{
rule.server = "dns_direct";
rule.strategy = dNSItem.SingboxStrategy4Direct.IsNullOrEmpty() ? null : dNSItem.SingboxStrategy4Direct;
+ if (!dNSItem.DirectExpectedIPs.IsNullOrEmpty())
+ {
+ rule.rule_set = new() { dNSItem.DirectExpectedIPs };
+ }
}
else if (item.OutboundTag == Global.ProxyTag)
{
diff --git a/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigV2rayService.cs b/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigV2rayService.cs
index 0374d74e..d2868be1 100644
--- a/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigV2rayService.cs
+++ b/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigV2rayService.cs
@@ -1,6 +1,8 @@
using System.Net;
using System.Net.NetworkInformation;
+using System.Text.Json;
using System.Text.Json.Nodes;
+using System.Text.Json.Serialization;
namespace ServiceLib.Services.CoreConfig;
@@ -1282,30 +1284,37 @@ public class CoreConfigV2rayService
v2rayConfig.dns ??= new Dns4Ray();
v2rayConfig.dns.servers ??= new List