mirror of https://github.com/2dust/v2rayN
Fix dns (#7834)
parent
3eb49aa24c
commit
cddf88730f
|
@ -80,25 +80,31 @@ public partial class CoreConfigSingboxService
|
||||||
hostsDns.predefined = Global.PredefinedHosts;
|
hostsDns.predefined = Global.PredefinedHosts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (simpleDNSItem.UseSystemHosts == true)
|
||||||
|
{
|
||||||
|
var systemHosts = Utils.GetSystemHosts();
|
||||||
|
if (systemHosts != null && systemHosts.Count > 0)
|
||||||
|
{
|
||||||
|
foreach (var host in systemHosts)
|
||||||
|
{
|
||||||
|
hostsDns.predefined.TryAdd(host.Key, new List<string> { host.Value });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!simpleDNSItem.Hosts.IsNullOrEmpty())
|
if (!simpleDNSItem.Hosts.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
var userHostsMap = simpleDNSItem.Hosts?
|
var userHostsMap = simpleDNSItem.Hosts
|
||||||
.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries)
|
.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries)
|
||||||
.Where(line => !string.IsNullOrWhiteSpace(line))
|
.Select(line => line.Trim())
|
||||||
.Where(line => line.Contains(' '))
|
.Where(line => !string.IsNullOrWhiteSpace(line) && line.Contains(' '))
|
||||||
|
.Select(line => line.Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries))
|
||||||
|
.Where(parts => parts.Length >= 2)
|
||||||
|
.GroupBy(parts => parts[0])
|
||||||
.ToDictionary(
|
.ToDictionary(
|
||||||
line =>
|
group => group.Key,
|
||||||
{
|
group => group.SelectMany(parts => parts.Skip(1)).ToList()
|
||||||
var parts = line.Trim().Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
|
);
|
||||||
return parts[0];
|
|
||||||
},
|
|
||||||
line =>
|
|
||||||
{
|
|
||||||
var parts = line.Trim().Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
|
|
||||||
var values = parts.Skip(1).ToList();
|
|
||||||
return values;
|
|
||||||
}
|
|
||||||
) ?? new Dictionary<string, List<string>>();
|
|
||||||
|
|
||||||
foreach (var kvp in userHostsMap)
|
foreach (var kvp in userHostsMap)
|
||||||
{
|
{
|
||||||
|
@ -106,22 +112,6 @@ public partial class CoreConfigSingboxService
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (simpleDNSItem.UseSystemHosts == true)
|
|
||||||
{
|
|
||||||
var systemHosts = Utils.GetSystemHosts();
|
|
||||||
if (systemHosts.Count > 0)
|
|
||||||
{
|
|
||||||
foreach (var host in systemHosts)
|
|
||||||
{
|
|
||||||
if (hostsDns.predefined[host.Key] != null)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
hostsDns.predefined[host.Key] = new List<string> { host.Value };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var host in hostsDns.predefined)
|
foreach (var host in hostsDns.predefined)
|
||||||
{
|
{
|
||||||
if (finalDns.server == host.Key)
|
if (finalDns.server == host.Key)
|
||||||
|
|
|
@ -248,43 +248,31 @@ public partial class CoreConfigV2rayService
|
||||||
if (simpleDNSItem.UseSystemHosts == true)
|
if (simpleDNSItem.UseSystemHosts == true)
|
||||||
{
|
{
|
||||||
var systemHosts = Utils.GetSystemHosts();
|
var systemHosts = Utils.GetSystemHosts();
|
||||||
if (systemHosts.Count > 0)
|
var normalHost = v2rayConfig?.dns?.hosts;
|
||||||
|
|
||||||
|
if (normalHost != null && systemHosts?.Count > 0)
|
||||||
{
|
{
|
||||||
var normalHost = v2rayConfig.dns.hosts;
|
foreach (var host in systemHosts)
|
||||||
if (normalHost != null)
|
|
||||||
{
|
{
|
||||||
foreach (var host in systemHosts)
|
normalHost.TryAdd(host.Key, new List<string> { host.Value });
|
||||||
{
|
|
||||||
if (normalHost[host.Key] != null)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
normalHost[host.Key] = new List<string> { host.Value };
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var userHostsMap = simpleDNSItem.Hosts?
|
if (!simpleDNSItem.Hosts.IsNullOrEmpty())
|
||||||
.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries)
|
|
||||||
.Where(line => !string.IsNullOrWhiteSpace(line))
|
|
||||||
.Where(line => line.Contains(' '))
|
|
||||||
.ToDictionary(
|
|
||||||
line =>
|
|
||||||
{
|
|
||||||
var parts = line.Trim().Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
|
|
||||||
return parts[0];
|
|
||||||
},
|
|
||||||
line =>
|
|
||||||
{
|
|
||||||
var parts = line.Trim().Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
|
|
||||||
var values = parts.Skip(1).ToList();
|
|
||||||
return values;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
if (userHostsMap != null)
|
|
||||||
{
|
{
|
||||||
|
var userHostsMap = simpleDNSItem.Hosts
|
||||||
|
.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries)
|
||||||
|
.Select(line => line.Trim())
|
||||||
|
.Where(line => !string.IsNullOrWhiteSpace(line) && line.Contains(' '))
|
||||||
|
.Select(line => line.Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries))
|
||||||
|
.Where(parts => parts.Length >= 2)
|
||||||
|
.GroupBy(parts => parts[0])
|
||||||
|
.ToDictionary(
|
||||||
|
group => group.Key,
|
||||||
|
group => group.SelectMany(parts => parts.Skip(1)).ToList()
|
||||||
|
);
|
||||||
|
|
||||||
foreach (var kvp in userHostsMap)
|
foreach (var kvp in userHostsMap)
|
||||||
{
|
{
|
||||||
v2rayConfig.dns.hosts[kvp.Key] = kvp.Value;
|
v2rayConfig.dns.hosts[kvp.Key] = kvp.Value;
|
||||||
|
|
Loading…
Reference in New Issue