diff --git a/FastGithub.Dns/DnsOptions.cs b/FastGithub.Dns/DnsOptions.cs
index d249c89..ed4316f 100644
--- a/FastGithub.Dns/DnsOptions.cs
+++ b/FastGithub.Dns/DnsOptions.cs
@@ -28,5 +28,10 @@ namespace FastGithub.Dns
/// 是否使用反向代理访问github
///
public bool UseGithubReverseProxy { get; set; }
+
+ ///
+ /// dns响应的反向代理服务的ip
+ ///
+ public IPAddress GithubReverseProxyIPAddress { get; set; } = IPAddress.Loopback;
}
}
diff --git a/FastGithub.Dns/GithubRequestResolver.cs b/FastGithub.Dns/GithubRequestResolver.cs
index 37c54c3..abdd2dc 100644
--- a/FastGithub.Dns/GithubRequestResolver.cs
+++ b/FastGithub.Dns/GithubRequestResolver.cs
@@ -7,8 +7,6 @@ using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using System;
using System.Linq;
-using System.Net;
-using System.Net.Sockets;
using System.Threading;
using System.Threading.Tasks;
@@ -46,20 +44,20 @@ namespace FastGithub.Dns
///
///
///
- public async Task Resolve(IRequest request, CancellationToken cancellationToken = default)
+ public Task Resolve(IRequest request, CancellationToken cancellationToken = default)
{
- var response = Response.FromRequest(request);
+ IResponse response = Response.FromRequest(request);
var question = request.Questions.FirstOrDefault();
if (question == null || question.Type != RecordType.A)
{
- return response;
+ return Task.FromResult(response);
}
var domain = question.Name.ToString();
if (this.githubResolver.IsSupported(domain) == false)
{
- return response;
+ return Task.FromResult(response);
}
if (this.options.CurrentValue.UseGithubReverseProxy == false)
@@ -75,7 +73,7 @@ namespace FastGithub.Dns
}
else
{
- var address = await GetLocalHostAddress();
+ var address = this.options.CurrentValue.GithubReverseProxyIPAddress;
var record = new IPAddressResourceRecord(question.Name, address, TimeSpan.FromMinutes(1));
response.AnswerRecords.Add(record);
this.logger.LogInformation($"[{domain}->{address}]");
@@ -85,26 +83,7 @@ namespace FastGithub.Dns
{
this.logger.LogWarning($"无法获得{domain}的最快ip");
}
- return response;
- }
-
- ///
- /// 获取本机ip
- ///
- ///
- private static async Task GetLocalHostAddress()
- {
- try
- {
- var localhost = System.Net.Dns.GetHostName();
- var addresses = await System.Net.Dns.GetHostAddressesAsync(localhost);
- var address = addresses.FirstOrDefault(item => item.AddressFamily == AddressFamily.InterNetwork);
- return address ?? IPAddress.Loopback;
- }
- catch (Exception)
- {
- return IPAddress.Loopback;
- }
+ return Task.FromResult(response);
}
}
}
diff --git a/FastGithub/README.MD b/FastGithub/README.MD
index 1653a84..79419fd 100644
--- a/FastGithub/README.MD
+++ b/FastGithub/README.MD
@@ -1,11 +1,12 @@
# FastGithub
github定制版的dns服务,解析github最优的ip
-### 本机使用
+### 本机使用[推荐]
* 运行FastGithub程序,本机的网络适配器的dns会自动变成127.0.0.1
* 如果网络适配器的dns没有变成127.0.0.1,请手工修改网络适配器的dns
### 局域网服务器使用
+* 修改appsettings.json文件的`Dns:GithubReverseProxyIPAddress`为局域网ip
* 在局域网服务器运行FastGithub程序
* 手工修改你电脑的网络适配器的dns,值为局域网服务器的ip
* 在你的电脑安装FastGithub.cer到`将所有的证书都放入下载存储\受信任的根证书颁发机构`
diff --git a/FastGithub/appsettings.json b/FastGithub/appsettings.json
index 9ce2715..3a04cc0 100644
--- a/FastGithub/appsettings.json
+++ b/FastGithub/appsettings.json
@@ -3,7 +3,8 @@
"UpStream": "114.114.114.114", // dns
"GithubTTL": "00:10:00", // githubĴʱ
"SetToLocalMachine": true, // Ƿñʹôdns(֧windows)
- "UseGithubReverseProxy": true // Ƿʹ÷githubԽӱظ
+ "UseGithubReverseProxy": true, // Ƿʹ÷githubԽӱظ
+ "GithubReverseProxyIPAddress": "127.0.0.1" // dnsӦķipʱҪдip
},
"Lookup": { // ip
"IPAddressComProvider": {