https://github.com/2dust/v2rayN/discussions/5268
This commit is contained in:
2dust 2024-06-27 17:59:39 +08:00
parent 691b19b5fd
commit 324f46cdad
2 changed files with 25 additions and 13 deletions

View file

@ -825,7 +825,7 @@ namespace v2rayN.Handler.CoreConfig
} }
singboxConfig.dns = dns4Sbox; singboxConfig.dns = dns4Sbox;
GenDnsDomains(singboxConfig); GenDnsDomains(node, singboxConfig);
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -834,33 +834,44 @@ namespace v2rayN.Handler.CoreConfig
return 0; return 0;
} }
private int GenDnsDomains(SingboxConfig singboxConfig) private int GenDnsDomains(ProfileItem? node, SingboxConfig singboxConfig)
{ {
var dns4Sbox = singboxConfig.dns ?? new(); var dns4Sbox = singboxConfig.dns ?? new();
dns4Sbox.servers ??= []; dns4Sbox.servers ??= [];
dns4Sbox.rules ??= []; dns4Sbox.rules ??= [];
var tag = "local_local";
dns4Sbox.servers.Add(new()
{
tag = tag,
address = "223.5.5.5",
detour = Global.DirectTag,
//strategy = strategy
});
var lstDomain = singboxConfig.outbounds var lstDomain = singboxConfig.outbounds
.Where(t => !Utils.IsNullOrEmpty(t.server) && Utils.IsDomain(t.server)) .Where(t => !Utils.IsNullOrEmpty(t.server) && Utils.IsDomain(t.server))
.Select(t => t.server) .Select(t => t.server)
.ToList(); .ToList();
if (lstDomain != null && lstDomain.Count > 0) if (lstDomain != null && lstDomain.Count > 0)
{ {
//var strategy = dns4Sbox.servers.Where(t => !Utils.IsNullOrEmpty(t.strategy)).Select(t => t.strategy).FirstOrDefault(); dns4Sbox.rules.Insert(0, new()
var tag = "local_local";
dns4Sbox.servers.Add(new()
{
tag = tag,
address = "223.5.5.5",
detour = Global.DirectTag,
//strategy = strategy
});
dns4Sbox.rules.Add(new()
{ {
server = tag, server = tag,
domain = lstDomain domain = lstDomain
}); });
} }
//Tun2SocksAddress
if (_config.tunModeItem.enableTun && node?.configType == EConfigType.Socks && Utils.IsDomain(node?.sni))
{
dns4Sbox.rules.Insert(0, new()
{
server = tag,
domain = [node?.sni]
});
}
singboxConfig.dns = dns4Sbox; singboxConfig.dns = dns4Sbox;
return 0; return 0;
} }
@ -1120,7 +1131,7 @@ namespace v2rayN.Handler.CoreConfig
singboxConfig.route.rules.Add(rule); singboxConfig.route.rules.Add(rule);
} }
GenDnsDomains(singboxConfig); GenDnsDomains(null, singboxConfig);
//var dnsServer = singboxConfig.dns?.servers.FirstOrDefault(); //var dnsServer = singboxConfig.dns?.servers.FirstOrDefault();
//if (dnsServer != null) //if (dnsServer != null)
//{ //{

View file

@ -218,6 +218,7 @@ namespace v2rayN.Handler
coreType = preCoreType, coreType = preCoreType,
configType = EConfigType.Socks, configType = EConfigType.Socks,
address = Global.Loopback, address = Global.Loopback,
sni = node.address, //Tun2SocksAddress
port = LazyConfig.Instance.GetLocalPort(EInboundProtocol.socks) port = LazyConfig.Instance.GetLocalPort(EInboundProtocol.socks)
}; };
} }