增加本机刷新域名的dns功能
This commit is contained in:
parent
4b025a60c1
commit
f45b880232
47
FastGithub.Scanner/GithubDnsFlushService.cs
Normal file
47
FastGithub.Scanner/GithubDnsFlushService.cs
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Microsoft.Extensions.Options;
|
||||||
|
using System;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Runtime.Versioning;
|
||||||
|
|
||||||
|
namespace FastGithub.Scanner
|
||||||
|
{
|
||||||
|
[Service(ServiceLifetime.Singleton)]
|
||||||
|
sealed class GithubDnsFlushService
|
||||||
|
{
|
||||||
|
private readonly ILogger<GithubDnsFlushService> logger;
|
||||||
|
private readonly IOptionsMonitor<GithubLookupFactoryOptions> options;
|
||||||
|
|
||||||
|
[SupportedOSPlatform("windows")]
|
||||||
|
[DllImport("dnsapi.dll", EntryPoint = "DnsFlushResolverCacheEntry_A", CharSet = CharSet.Ansi)]
|
||||||
|
private static extern int DnsFlushResolverCacheEntry(string hostName);
|
||||||
|
|
||||||
|
public GithubDnsFlushService(
|
||||||
|
ILogger<GithubDnsFlushService> logger,
|
||||||
|
IOptionsMonitor<GithubLookupFactoryOptions> options)
|
||||||
|
{
|
||||||
|
this.logger = logger;
|
||||||
|
this.options = options;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void FlushGithubResolverCache()
|
||||||
|
{
|
||||||
|
if (OperatingSystem.IsWindows())
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
foreach (var domain in this.options.CurrentValue.Domains)
|
||||||
|
{
|
||||||
|
DnsFlushResolverCacheEntry(domain);
|
||||||
|
}
|
||||||
|
this.logger.LogInformation($"刷新本机相关域名的dns缓存成功");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
this.logger.LogWarning($"刷新本机相关域名的dns缓存失败:{ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -17,6 +17,7 @@ namespace FastGithub.Scanner
|
|||||||
{
|
{
|
||||||
private readonly GithubLookupFacotry lookupFactory;
|
private readonly GithubLookupFacotry lookupFactory;
|
||||||
private readonly GithubScanResults scanResults;
|
private readonly GithubScanResults scanResults;
|
||||||
|
private readonly GithubDnsFlushService dnsFlushService;
|
||||||
private readonly ILoggerFactory loggerFactory;
|
private readonly ILoggerFactory loggerFactory;
|
||||||
private readonly ILogger<GithubScanService> logger;
|
private readonly ILogger<GithubScanService> logger;
|
||||||
|
|
||||||
@ -33,12 +34,14 @@ namespace FastGithub.Scanner
|
|||||||
public GithubScanService(
|
public GithubScanService(
|
||||||
GithubLookupFacotry lookupFactory,
|
GithubLookupFacotry lookupFactory,
|
||||||
GithubScanResults scanResults,
|
GithubScanResults scanResults,
|
||||||
|
GithubDnsFlushService dnsFlushService,
|
||||||
IServiceProvider appService,
|
IServiceProvider appService,
|
||||||
ILoggerFactory loggerFactory,
|
ILoggerFactory loggerFactory,
|
||||||
ILogger<GithubScanService> logger)
|
ILogger<GithubScanService> logger)
|
||||||
{
|
{
|
||||||
this.lookupFactory = lookupFactory;
|
this.lookupFactory = lookupFactory;
|
||||||
this.scanResults = scanResults;
|
this.scanResults = scanResults;
|
||||||
|
this.dnsFlushService = dnsFlushService;
|
||||||
this.loggerFactory = loggerFactory;
|
this.loggerFactory = loggerFactory;
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
|
|
||||||
@ -156,7 +159,7 @@ namespace FastGithub.Scanner
|
|||||||
domainLogger.LogWarning(context.ToStatisticsString());
|
domainLogger.LogWarning(context.ToStatisticsString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
this.dnsFlushService.FlushGithubResolverCache();
|
||||||
this.logger.LogInformation($"结果扫描结束,共扫描{results.Length}条记录");
|
this.logger.LogInformation($"结果扫描结束,共扫描{results.Length}条记录");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user