From 4ce79fa5d6f12a82b44bf4080e31636fd04ad711 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=9B=BD=E4=BC=9F?= <366193849@qq.com> Date: Thu, 15 Jul 2021 13:53:49 +0800 Subject: [PATCH] fix ip config --- FastGithub.Dns/DnsHostedService.cs | 4 ++-- FastGithub.Dns/DnsOptions.cs | 6 +++--- FastGithub.Dns/GithubRequestResolver.cs | 10 +++------- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/FastGithub.Dns/DnsHostedService.cs b/FastGithub.Dns/DnsHostedService.cs index 7bd1c14..cbb8919 100644 --- a/FastGithub.Dns/DnsHostedService.cs +++ b/FastGithub.Dns/DnsHostedService.cs @@ -40,7 +40,7 @@ namespace FastGithub.Dns { this.options = options; this.logger = logger; - this.requestResolver = new CompositeRequestResolver(options.Value.UpStream, githubRequestResolver); + this.requestResolver = new CompositeRequestResolver(IPAddress.Parse(options.Value.UpStream), githubRequestResolver); } /// @@ -57,7 +57,7 @@ namespace FastGithub.Dns } this.logger.LogInformation("dns服务启动成功"); - this.dnsAddresses = this.SetNameServers(IPAddress.Loopback, this.options.Value.UpStream); + this.dnsAddresses = this.SetNameServers(IPAddress.Loopback, IPAddress.Parse(this.options.Value.UpStream)); return base.StartAsync(cancellationToken); } diff --git a/FastGithub.Dns/DnsOptions.cs b/FastGithub.Dns/DnsOptions.cs index ed4316f..03ce16e 100644 --- a/FastGithub.Dns/DnsOptions.cs +++ b/FastGithub.Dns/DnsOptions.cs @@ -12,7 +12,7 @@ namespace FastGithub.Dns /// /// 获取或设置上游ip地址 /// - public IPAddress UpStream { get; set; } = IPAddress.Parse("114.114.114.114"); + public string UpStream { get; set; } = "114.114.114.114"; /// /// 获取或设置github相关域名的ip存活时长 @@ -27,11 +27,11 @@ namespace FastGithub.Dns /// /// 是否使用反向代理访问github /// - public bool UseGithubReverseProxy { get; set; } + public bool UseGithubReverseProxy { get; set; } = true; /// /// dns响应的反向代理服务的ip /// - public IPAddress GithubReverseProxyIPAddress { get; set; } = IPAddress.Loopback; + public string GithubReverseProxyIPAddress { get; set; } = IPAddress.Loopback.ToString(); } } diff --git a/FastGithub.Dns/GithubRequestResolver.cs b/FastGithub.Dns/GithubRequestResolver.cs index abdd2dc..6f7d4e0 100644 --- a/FastGithub.Dns/GithubRequestResolver.cs +++ b/FastGithub.Dns/GithubRequestResolver.cs @@ -7,6 +7,7 @@ using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using System; using System.Linq; +using System.Net; using System.Threading; using System.Threading.Tasks; @@ -73,16 +74,11 @@ namespace FastGithub.Dns } else { - var address = this.options.CurrentValue.GithubReverseProxyIPAddress; + var address = IPAddress.Parse(this.options.CurrentValue.GithubReverseProxyIPAddress); var record = new IPAddressResourceRecord(question.Name, address, TimeSpan.FromMinutes(1)); response.AnswerRecords.Add(record); this.logger.LogInformation($"[{domain}->{address}]"); - } - - if (response.AnswerRecords.Count == 0) - { - this.logger.LogWarning($"无法获得{domain}的最快ip"); - } + } return Task.FromResult(response); } }