diff --git a/FastGithub.Scanner/LoopbackDnsHttpHandler.cs b/FastGithub.Scanner/GithubDnsHttpHandler.cs
similarity index 53%
rename from FastGithub.Scanner/LoopbackDnsHttpHandler.cs
rename to FastGithub.Scanner/GithubDnsHttpHandler.cs
index 529d390..abb498b 100644
--- a/FastGithub.Scanner/LoopbackDnsHttpHandler.cs
+++ b/FastGithub.Scanner/GithubDnsHttpHandler.cs
@@ -1,8 +1,5 @@
-using DNS.Client;
-using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.DependencyInjection;
using System;
-using System.Linq;
-using System.Net;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
@@ -10,15 +7,21 @@ using System.Threading.Tasks;
namespace FastGithub.Scanner
{
///
- /// 由本程序提值的dns的httpHandler
+ /// Github的dns解析的httpHandler
+ /// 使扫描索结果作为github的https请求的域名解析
///
[Service(ServiceLifetime.Transient)]
- sealed class LoopbackDnsHttpHandler : DelegatingHandler
+ sealed class GithubDnsHttpHandler : DelegatingHandler
{
+ private readonly GithubContextCollection scanResults;
+
///
- /// 本程序的dns
+ /// Github的dns解析的httpHandler
///
- private static readonly DnsClient dnsClient = new(IPAddress.Loopback);
+ public GithubDnsHttpHandler(GithubContextCollection scanResults)
+ {
+ this.scanResults = scanResults;
+ }
///
/// 发送消息
@@ -31,7 +34,7 @@ namespace FastGithub.Scanner
var uri = request.RequestUri;
if (uri != null && uri.HostNameType == UriHostNameType.Dns)
{
- var address = await LookupAsync(uri.Host);
+ var address = this.scanResults.FindBestAddress(uri.Host);
if (address != null)
{
var builder = new UriBuilder(uri)
@@ -45,24 +48,5 @@ namespace FastGithub.Scanner
return await base.SendAsync(request, cancellationToken);
}
-
- ///
- /// dns解析ip
- ///
- ///
- ///
- private static async Task LookupAsync(string host)
- {
- try
- {
- using var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromMilliseconds(500d));
- var addresses = await dnsClient.Lookup(host, cancellationToken: cancellationTokenSource.Token);
- return addresses.FirstOrDefault();
- }
- catch (Exception)
- {
- return default;
- }
- }
}
}
diff --git a/FastGithub.Scanner/ScannerServiceCollectionExtensions.cs b/FastGithub.Scanner/ScannerServiceCollectionExtensions.cs
index f5cda97..ca46c4d 100644
--- a/FastGithub.Scanner/ScannerServiceCollectionExtensions.cs
+++ b/FastGithub.Scanner/ScannerServiceCollectionExtensions.cs
@@ -37,7 +37,7 @@ namespace FastGithub
UseProxy = false,
AllowAutoRedirect = false
})
- .AddHttpMessageHandler();
+ .AddHttpMessageHandler();
return services
.AddMemoryCache()