mirror of
https://github.com/netchx/netch.git
synced 2026-03-14 17:43:18 +08:00
Rename DNS to DnsUtils
This commit is contained in:
@@ -61,7 +61,7 @@ namespace Netch.Controllers
|
||||
// 刷新DNS缓存
|
||||
NativeMethods.FlushDNSResolverCache();
|
||||
|
||||
if (DNS.Lookup(server.Hostname) == null)
|
||||
if (DnsUtils.Lookup(server.Hostname) == null)
|
||||
throw new MessageException(i18N.Translate("Lookup Server hostname failed"));
|
||||
|
||||
// 添加Netch到防火墙
|
||||
|
||||
@@ -42,7 +42,7 @@ namespace Netch.Controllers
|
||||
public void Start(in Mode mode)
|
||||
{
|
||||
var server = MainController.Server!;
|
||||
_serverAddresses = DNS.Lookup(server.Hostname)!; // server address have been cached when MainController.Start
|
||||
_serverAddresses = DnsUtils.Lookup(server.Hostname)!; // server address have been cached when MainController.Start
|
||||
|
||||
if (TUNTAP.GetComponentID() == null)
|
||||
TUNTAP.AddTap();
|
||||
@@ -72,7 +72,7 @@ namespace Netch.Controllers
|
||||
argument.Append($"-proxyServer 127.0.0.1:{Global.Settings.Socks5LocalPort} ");
|
||||
|
||||
argument.Append(
|
||||
$"-tunAddr {Global.Settings.TUNTAP.Address} -tunMask {Global.Settings.TUNTAP.Netmask} -tunGw {Global.Settings.TUNTAP.Gateway} -tunDns {DNS.Join(dns)} -tunName \"{TUNTAP.GetName(_tap.ComponentID)}\" ");
|
||||
$"-tunAddr {Global.Settings.TUNTAP.Address} -tunMask {Global.Settings.TUNTAP.Netmask} -tunGw {Global.Settings.TUNTAP.Gateway} -tunDns {DnsUtils.Join(dns)} -tunName \"{TUNTAP.GetName(_tap.ComponentID)}\" ");
|
||||
|
||||
if (Global.Settings.TUNTAP.UseFakeDNS && Global.Flags.SupportFakeDns)
|
||||
argument.Append("-fakeDns ");
|
||||
|
||||
@@ -414,7 +414,7 @@ namespace Netch.Forms
|
||||
await Task.Run(() =>
|
||||
{
|
||||
NativeMethods.FlushDNSResolverCache();
|
||||
DNS.Cache.Clear();
|
||||
DnsUtils.ClearCache();
|
||||
});
|
||||
|
||||
NotifyTip(i18N.Translate("DNS cache cleanup succeeded"));
|
||||
|
||||
@@ -86,7 +86,7 @@ namespace Netch.Forms
|
||||
|
||||
BindCheckBox(ModifySystemDNSCheckBox, b => Global.Settings.ModifySystemDNS = b, Global.Settings.ModifySystemDNS);
|
||||
|
||||
BindTextBox(ModifiedDNSTextBox, s => DNS.TrySplit(s, out _, 2), s => Global.Settings.ModifiedDNS = s, Global.Settings.ModifiedDNS);
|
||||
BindTextBox(ModifiedDNSTextBox, s => DnsUtils.TrySplit(s, out _, 2), s => Global.Settings.ModifiedDNS = s, Global.Settings.ModifiedDNS);
|
||||
|
||||
BindCheckBox(RedirectorSSCheckBox, s => Global.Settings.RedirectorSS = s, Global.Settings.RedirectorSS);
|
||||
|
||||
@@ -116,13 +116,13 @@ namespace Netch.Forms
|
||||
BindCheckBox(UseCustomDNSCheckBox, b => { Global.Settings.TUNTAP.UseCustomDNS = b; }, Global.Settings.TUNTAP.UseCustomDNS);
|
||||
|
||||
BindTextBox(TUNTAPDNSTextBox,
|
||||
s => !UseCustomDNSCheckBox.Checked || DNS.TrySplit(s, out _, 2),
|
||||
s => !UseCustomDNSCheckBox.Checked || DnsUtils.TrySplit(s, out _, 2),
|
||||
s =>
|
||||
{
|
||||
if (UseCustomDNSCheckBox.Checked)
|
||||
Global.Settings.TUNTAP.DNS = DNS.Split(s).ToList();
|
||||
Global.Settings.TUNTAP.DNS = DnsUtils.Split(s).ToList();
|
||||
},
|
||||
DNS.Join(Global.Settings.TUNTAP.DNS));
|
||||
DnsUtils.Join(Global.Settings.TUNTAP.DNS));
|
||||
|
||||
BindCheckBox(ProxyDNSCheckBox, b => Global.Settings.TUNTAP.ProxyDNS = b, Global.Settings.TUNTAP.ProxyDNS);
|
||||
BindCheckBox(UseFakeDNSCheckBox, b => Global.Settings.TUNTAP.UseFakeDNS = b, Global.Settings.TUNTAP.UseFakeDNS);
|
||||
@@ -204,7 +204,7 @@ namespace Netch.Forms
|
||||
private void TUNTAPUseCustomDNSCheckBox_CheckedChanged(object? sender, EventArgs? e)
|
||||
{
|
||||
if (UseCustomDNSCheckBox.Checked)
|
||||
TUNTAPDNSTextBox.Text = Global.Settings.TUNTAP.DNS.Any() ? DNS.Join(Global.Settings.TUNTAP.DNS) : "1.1.1.1";
|
||||
TUNTAPDNSTextBox.Text = Global.Settings.TUNTAP.DNS.Any() ? DnsUtils.Join(Global.Settings.TUNTAP.DNS) : "1.1.1.1";
|
||||
else
|
||||
TUNTAPDNSTextBox.Text = "AioDNS";
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ namespace Netch.Models
|
||||
{
|
||||
try
|
||||
{
|
||||
var destination = DNS.Lookup(Hostname);
|
||||
var destination = DnsUtils.Lookup(Hostname);
|
||||
if (destination == null)
|
||||
return Delay = -2;
|
||||
|
||||
@@ -122,7 +122,7 @@ namespace Netch.Models
|
||||
{
|
||||
public static string AutoResolveHostname(this Server server)
|
||||
{
|
||||
return Global.Settings.ResolveServerHostname ? DNS.Lookup(server.Hostname)!.ToString() : server.Hostname;
|
||||
return Global.Settings.ResolveServerHostname ? DnsUtils.Lookup(server.Hostname)!.ToString() : server.Hostname;
|
||||
}
|
||||
|
||||
public static bool Valid(this Server server)
|
||||
|
||||
@@ -6,12 +6,12 @@ using System.Net;
|
||||
|
||||
namespace Netch.Utils
|
||||
{
|
||||
public static class DNS
|
||||
public static class DnsUtils
|
||||
{
|
||||
/// <summary>
|
||||
/// 缓存
|
||||
/// </summary>
|
||||
public static Hashtable Cache = new();
|
||||
private static readonly Hashtable Cache = new();
|
||||
|
||||
/// <summary>
|
||||
/// 查询
|
||||
@@ -42,6 +42,16 @@ namespace Netch.Utils
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询
|
||||
/// </summary>
|
||||
/// <param name="hostname">主机名</param>
|
||||
/// <returns></returns>
|
||||
public static void ClearCache()
|
||||
{
|
||||
Cache.Clear();
|
||||
}
|
||||
|
||||
public static IEnumerable<string> Split(string dns)
|
||||
{
|
||||
return dns.SplitRemoveEmptyEntriesAndTrimEntries(',');
|
||||
@@ -84,7 +84,7 @@ namespace Netch.Utils
|
||||
}
|
||||
else
|
||||
{
|
||||
var dnsResult = DNS.Lookup(Hostname);
|
||||
var dnsResult = DnsUtils.Lookup(Hostname);
|
||||
|
||||
if (dnsResult != null)
|
||||
country = databaseReader.Country(dnsResult).Country.IsoCode;
|
||||
|
||||
Reference in New Issue
Block a user