mirror of https://github.com/2dust/v2rayN
Adjust sing-box dns
parent
568144d6a2
commit
c23379b3b6
|
@ -481,7 +481,7 @@ namespace v2rayN
|
||||||
/// 验证Domain地址是否合法
|
/// 验证Domain地址是否合法
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="domain"></param>
|
/// <param name="domain"></param>
|
||||||
public static bool IsDomain(string domain)
|
public static bool IsDomain(string? domain)
|
||||||
{
|
{
|
||||||
//如果为空
|
//如果为空
|
||||||
if (IsNullOrEmpty(domain))
|
if (IsNullOrEmpty(domain))
|
||||||
|
|
|
@ -810,24 +810,9 @@ namespace v2rayN.Handler
|
||||||
{
|
{
|
||||||
return 0;
|
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;
|
singboxConfig.dns = dns4Sbox;
|
||||||
|
|
||||||
|
GenDnsDomains(singboxConfig);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
@ -836,6 +821,35 @@ namespace v2rayN.Handler
|
||||||
return 0;
|
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)
|
private int GenExperimental(SingboxConfig singboxConfig)
|
||||||
{
|
{
|
||||||
if (_config.guiItem.enableStatistics)
|
if (_config.guiItem.enableStatistics)
|
||||||
|
@ -1076,18 +1090,18 @@ namespace v2rayN.Handler
|
||||||
singboxConfig.route.rules.Add(rule);
|
singboxConfig.route.rules.Add(rule);
|
||||||
}
|
}
|
||||||
|
|
||||||
GenDns(new(), singboxConfig);
|
GenDnsDomains(singboxConfig);
|
||||||
var dnsServer = singboxConfig.dns?.servers.FirstOrDefault();
|
//var dnsServer = singboxConfig.dns?.servers.FirstOrDefault();
|
||||||
if (dnsServer != null)
|
//if (dnsServer != null)
|
||||||
{
|
//{
|
||||||
dnsServer.detour = singboxConfig.route.rules.LastOrDefault()?.outbound;
|
// dnsServer.detour = singboxConfig.route.rules.LastOrDefault()?.outbound;
|
||||||
}
|
//}
|
||||||
var dnsRule = singboxConfig.dns?.rules.Where(t => t.outbound != null).FirstOrDefault();
|
//var dnsRule = singboxConfig.dns?.rules.Where(t => t.outbound != null).FirstOrDefault();
|
||||||
if (dnsRule != null)
|
//if (dnsRule != null)
|
||||||
{
|
//{
|
||||||
singboxConfig.dns.rules = [];
|
// singboxConfig.dns.rules = [];
|
||||||
singboxConfig.dns.rules.Add(dnsRule);
|
// singboxConfig.dns.rules.Add(dnsRule);
|
||||||
}
|
//}
|
||||||
|
|
||||||
//msg = string.Format(ResUI.SuccessfulConfiguration"), node.getSummary());
|
//msg = string.Format(ResUI.SuccessfulConfiguration"), node.getSummary());
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -95,7 +95,7 @@
|
||||||
{
|
{
|
||||||
public string type { get; set; }
|
public string type { get; set; }
|
||||||
public string tag { get; set; }
|
public string tag { get; set; }
|
||||||
public string server { get; set; }
|
public string? server { get; set; }
|
||||||
public int? server_port { get; set; }
|
public int? server_port { get; set; }
|
||||||
public string uuid { get; set; }
|
public string uuid { get; set; }
|
||||||
public string security { get; set; }
|
public string security { get; set; }
|
||||||
|
|
|
@ -30,5 +30,6 @@
|
||||||
],
|
],
|
||||||
"server": "block"
|
"server": "block"
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
"final": "local"
|
||||||
}
|
}
|
|
@ -30,5 +30,6 @@
|
||||||
],
|
],
|
||||||
"server": "block"
|
"server": "block"
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
"final": "local"
|
||||||
}
|
}
|
Loading…
Reference in New Issue