mirror of
				https://github.com/2dust/v2rayN.git
				synced 2025-10-31 04:22:51 +00:00 
			
		
		
		
	Adjust sing-box dns
This commit is contained in:
		
							parent
							
								
									568144d6a2
								
							
						
					
					
						commit
						c23379b3b6
					
				
					 5 changed files with 49 additions and 33 deletions
				
			
		|  | @ -481,7 +481,7 @@ namespace v2rayN | |||
|         /// 验证Domain地址是否合法 | ||||
|         /// </summary> | ||||
|         /// <param name="domain"></param> | ||||
|         public static bool IsDomain(string domain) | ||||
|         public static bool IsDomain(string? domain) | ||||
|         { | ||||
|             //如果为空 | ||||
|             if (IsNullOrEmpty(domain)) | ||||
|  |  | |||
|  | @ -810,24 +810,9 @@ namespace v2rayN.Handler | |||
|                 { | ||||
|                     return 0; | ||||
|                 } | ||||
|                 //Add the dns of the remote server domain | ||||
|                 if (dns4Sbox.rules is null) | ||||
|                 { | ||||
|                     dns4Sbox.rules = new(); | ||||
|                 } | ||||
|                 dns4Sbox.servers.Add(new() | ||||
|                 { | ||||
|                     tag = "local_local", | ||||
|                     address = "223.5.5.5", | ||||
|                     detour = Global.DirectTag, | ||||
|                 }); | ||||
|                 dns4Sbox.rules.Add(new() | ||||
|                 { | ||||
|                     server = "local_local", | ||||
|                     outbound = "any" | ||||
|                 }); | ||||
| 
 | ||||
|                 singboxConfig.dns = dns4Sbox; | ||||
| 
 | ||||
|                 GenDnsDomains(singboxConfig); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|  | @ -836,6 +821,35 @@ namespace v2rayN.Handler | |||
|             return 0; | ||||
|         } | ||||
| 
 | ||||
|         private int GenDnsDomains(SingboxConfig singboxConfig) | ||||
|         { | ||||
|             var dns4Sbox = singboxConfig.dns ?? new(); | ||||
|             dns4Sbox.servers ??= []; | ||||
|             dns4Sbox.rules ??= []; | ||||
| 
 | ||||
|             var lstDomain = singboxConfig.outbounds | ||||
|                            .Where(t => !Utils.IsNullOrEmpty(t.server) && Utils.IsDomain(t.server)) | ||||
|                            .Select(t => t.server) | ||||
|                            .ToList(); | ||||
|             if (lstDomain != null && lstDomain.Count > 0) | ||||
|             { | ||||
|                 var tag = "local_local"; | ||||
|                 dns4Sbox.servers.Insert(0, new() | ||||
|                 { | ||||
|                     tag = tag, | ||||
|                     address = "223.5.5.5", | ||||
|                     detour = Global.DirectTag, | ||||
|                 }); | ||||
|                 dns4Sbox.rules.Insert(0, new() | ||||
|                 { | ||||
|                     server = tag, | ||||
|                     domain = lstDomain | ||||
|                 }); | ||||
|             } | ||||
|             singboxConfig.dns = dns4Sbox; | ||||
|             return 0; | ||||
|         } | ||||
| 
 | ||||
|         private int GenExperimental(SingboxConfig singboxConfig) | ||||
|         { | ||||
|             if (_config.guiItem.enableStatistics) | ||||
|  | @ -1076,18 +1090,18 @@ namespace v2rayN.Handler | |||
|                     singboxConfig.route.rules.Add(rule); | ||||
|                 } | ||||
| 
 | ||||
|                 GenDns(new(), singboxConfig); | ||||
|                 var dnsServer = singboxConfig.dns?.servers.FirstOrDefault(); | ||||
|                 if (dnsServer != null) | ||||
|                 { | ||||
|                     dnsServer.detour = singboxConfig.route.rules.LastOrDefault()?.outbound; | ||||
|                 } | ||||
|                 var dnsRule = singboxConfig.dns?.rules.Where(t => t.outbound != null).FirstOrDefault(); | ||||
|                 if (dnsRule != null) | ||||
|                 { | ||||
|                     singboxConfig.dns.rules = []; | ||||
|                     singboxConfig.dns.rules.Add(dnsRule); | ||||
|                 } | ||||
|                 GenDnsDomains(singboxConfig); | ||||
|                 //var dnsServer = singboxConfig.dns?.servers.FirstOrDefault(); | ||||
|                 //if (dnsServer != null) | ||||
|                 //{ | ||||
|                 //    dnsServer.detour = singboxConfig.route.rules.LastOrDefault()?.outbound; | ||||
|                 //} | ||||
|                 //var dnsRule = singboxConfig.dns?.rules.Where(t => t.outbound != null).FirstOrDefault(); | ||||
|                 //if (dnsRule != null) | ||||
|                 //{ | ||||
|                 //    singboxConfig.dns.rules = []; | ||||
|                 //    singboxConfig.dns.rules.Add(dnsRule); | ||||
|                 //} | ||||
| 
 | ||||
|                 //msg = string.Format(ResUI.SuccessfulConfiguration"), node.getSummary()); | ||||
|                 return 0; | ||||
|  |  | |||
|  | @ -95,7 +95,7 @@ | |||
|     { | ||||
|         public string type { get; set; } | ||||
|         public string tag { get; set; } | ||||
|         public string server { get; set; } | ||||
|         public string? server { get; set; } | ||||
|         public int? server_port { get; set; } | ||||
|         public string uuid { get; set; } | ||||
|         public string security { get; set; } | ||||
|  |  | |||
|  | @ -30,5 +30,6 @@ | |||
|       ], | ||||
|       "server": "block" | ||||
|     } | ||||
|   ] | ||||
|   ], | ||||
|   "final": "local" | ||||
| } | ||||
|  | @ -30,5 +30,6 @@ | |||
|       ], | ||||
|       "server": "block" | ||||
|     } | ||||
|   ] | ||||
|   ], | ||||
|   "final": "local" | ||||
| } | ||||
		Loading…
	
		Reference in a new issue
	
	 2dust
						2dust