diff --git a/Netch/Controllers/MainController.cs b/Netch/Controllers/MainController.cs
index b94b2136..4ff02304 100644
--- a/Netch/Controllers/MainController.cs
+++ b/Netch/Controllers/MainController.cs
@@ -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到防火墙
diff --git a/Netch/Controllers/TUNTAPController.cs b/Netch/Controllers/TUNTAPController.cs
index b88499a5..5a2671df 100644
--- a/Netch/Controllers/TUNTAPController.cs
+++ b/Netch/Controllers/TUNTAPController.cs
@@ -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 ");
diff --git a/Netch/Forms/MainForm.cs b/Netch/Forms/MainForm.cs
index 046e12c6..ee23dc8a 100644
--- a/Netch/Forms/MainForm.cs
+++ b/Netch/Forms/MainForm.cs
@@ -414,7 +414,7 @@ namespace Netch.Forms
await Task.Run(() =>
{
NativeMethods.FlushDNSResolverCache();
- DNS.Cache.Clear();
+ DnsUtils.ClearCache();
});
NotifyTip(i18N.Translate("DNS cache cleanup succeeded"));
diff --git a/Netch/Forms/SettingForm.cs b/Netch/Forms/SettingForm.cs
index c368867d..b6ac08c4 100644
--- a/Netch/Forms/SettingForm.cs
+++ b/Netch/Forms/SettingForm.cs
@@ -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";
}
diff --git a/Netch/Models/Server.cs b/Netch/Models/Server.cs
index 79265cf4..320f0295 100644
--- a/Netch/Models/Server.cs
+++ b/Netch/Models/Server.cs
@@ -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)
diff --git a/Netch/Utils/DNS.cs b/Netch/Utils/DnsUtils.cs
similarity index 82%
rename from Netch/Utils/DNS.cs
rename to Netch/Utils/DnsUtils.cs
index 7eb0434b..5664da91 100644
--- a/Netch/Utils/DNS.cs
+++ b/Netch/Utils/DnsUtils.cs
@@ -6,12 +6,12 @@ using System.Net;
namespace Netch.Utils
{
- public static class DNS
+ public static class DnsUtils
{
///
/// 缓存
///
- public static Hashtable Cache = new();
+ private static readonly Hashtable Cache = new();
///
/// 查询
@@ -42,6 +42,16 @@ namespace Netch.Utils
}
}
+ ///
+ /// 查询
+ ///
+ /// 主机名
+ ///
+ public static void ClearCache()
+ {
+ Cache.Clear();
+ }
+
public static IEnumerable Split(string dns)
{
return dns.SplitRemoveEmptyEntriesAndTrimEntries(',');
diff --git a/Netch/Utils/Utils.cs b/Netch/Utils/Utils.cs
index 0ee22a92..786bc7bb 100644
--- a/Netch/Utils/Utils.cs
+++ b/Netch/Utils/Utils.cs
@@ -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;