Skip to content

Commit

Permalink
Add feature: round roll pulling from the candidate dns server list
Browse files Browse the repository at this point in the history
  • Loading branch information
huangxiangyao committed Sep 5, 2023
1 parent a75811c commit dc2558f
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 7 deletions.
5 changes: 5 additions & 0 deletions src/IpFix/Myvas.Tools.IpFix.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
<ImplicitUsings>enable</ImplicitUsings>
<!--<Nullable>enable</Nullable>-->
<Applicationmanifest>app.manifest</Applicationmanifest>
<Authors>FrankH &lt;[email protected]&gt;</Authors>
<Company>Myvas Foundation</Company>
<RunAnalyzersDuringLiveAnalysis>False</RunAnalyzersDuringLiveAnalysis>
<RunAnalyzersDuringBuild>False</RunAnalyzersDuringBuild>
<EnableNETAnalyzers>False</EnableNETAnalyzers>
</PropertyGroup>

<ItemGroup>
Expand Down
54 changes: 48 additions & 6 deletions src/IpFix/Program.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,57 @@
using System.Diagnostics;
using System.Reflection;

namespace Myvas.Tools.IpFix;

public static class Program
{
/// <summary>
/// Best free public DNS servers: https://www.lifewire.com/free-and-public-dns-servers-2626062
/// </summary>
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<string> ReadNameServersFromFile()
{
var result = new List<string>();
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<string>(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
Expand Down Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion src/IpFix/app.manifest
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity version="1.0.0.0" name="ipfix"/>
<description>We should run as administrator mode, in order to update your 'hosts' file probably.</description>

<!-- Identify the application security requirements. -->
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
Expand Down

0 comments on commit dc2558f

Please sign in to comment.