diff --git a/src/IpFix/Myvas.Tools.IpFix.csproj b/src/IpFix/Myvas.Tools.IpFix.csproj index 48c06f7..de12106 100644 --- a/src/IpFix/Myvas.Tools.IpFix.csproj +++ b/src/IpFix/Myvas.Tools.IpFix.csproj @@ -7,6 +7,11 @@ enable app.manifest + FrankH <4848285@qq.com> + Myvas Foundation + False + False + False diff --git a/src/IpFix/Program.cs b/src/IpFix/Program.cs index f0917da..4c47506 100644 --- a/src/IpFix/Program.cs +++ b/src/IpFix/Program.cs @@ -1,14 +1,57 @@ +using System.Diagnostics; using System.Reflection; namespace Myvas.Tools.IpFix; public static class Program { + /// + /// Best free public DNS servers: https://www.lifewire.com/free-and-public-dns-servers-2626062 + /// static string[] CandidateNameServers = new[] { "8.8.8.8", "76.76.2.0", "9.9.9.9", "208.67.222.222", "1.1.1.1", "185.228.168.9", "76.76.19.19", "94.140.14.14" }; + static List ReadNameServersFromFile() + { + var result = new List(); + var path = AppDomain.CurrentDomain.BaseDirectory; + Debug.WriteLine(path); + var filename = Path.Combine(path, "ipfix.data"); + try + { + using var sr = new StreamReader(filename); + string line = null; + while ((line = sr.ReadLine()) != null) + { + result.Add(line); + } + sr.Close(); + } + catch { } + var count = result.Count; + if (count < 2) + { + result = new List(CandidateNameServers); + count = result.Count; + } + try + { + var sw = new StreamWriter(filename); + for (var i = 1; i < count; i++) + { + sw.WriteLine(result[i]); + } + sw.WriteLine(result[0]); + sw.Close(); + } + catch + { + } + return result; + } + static async Task Main(string[] args) { // e.g. ipfix github.com @@ -83,22 +126,21 @@ static async Task Main(string[] args) Console.WriteLine("Press any key to exit..."); Console.ReadKey(); } - finally - { - } } public static async Task FixAsync(string dns) { string ipAddress = ""; IFetcher fetcher = new NslookupExeFetcher(); - // Best free public DNS servers: https://www.lifewire.com/free-and-public-dns-servers-2626062 - foreach (var selectedNameSever in CandidateNameServers) + var candidateNameServers = ReadNameServersFromFile(); + var count = candidateNameServers.Count; + for (var i = 0; i < count; i++) { + if (i != 0) candidateNameServers = ReadNameServersFromFile(); try { - ((NslookupExeFetcher)fetcher).SelectedNameServer = selectedNameSever; + ((NslookupExeFetcher)fetcher).SelectedNameServer = candidateNameServers[0]; Console.WriteLine($"Retrieving records via {fetcher}..."); ipAddress = await fetcher.RetrieveIpv4Async(dns); if (!string.IsNullOrWhiteSpace(ipAddress)) break; diff --git a/src/IpFix/app.manifest b/src/IpFix/app.manifest index 29bfdb9..05f8775 100644 --- a/src/IpFix/app.manifest +++ b/src/IpFix/app.manifest @@ -2,7 +2,6 @@ We should run as administrator mode, in order to update your 'hosts' file probably. -