手动配置ip

This commit is contained in:
陈国伟 2021-07-15 13:25:53 +08:00
parent acb18d7078
commit 6fb855f06f
4 changed files with 15 additions and 29 deletions

View File

@ -28,5 +28,10 @@ namespace FastGithub.Dns
/// 是否使用反向代理访问github
/// </summary>
public bool UseGithubReverseProxy { get; set; }
/// <summary>
/// dns响应的反向代理服务的ip
/// </summary>
public IPAddress GithubReverseProxyIPAddress { get; set; } = IPAddress.Loopback;
}
}

View File

@ -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
/// <param name="request"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task<IResponse> Resolve(IRequest request, CancellationToken cancellationToken = default)
public Task<IResponse> 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;
}
/// <summary>
/// 获取本机ip
/// </summary>
/// <returns></returns>
private static async Task<IPAddress> 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);
}
}
}

View File

@ -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到`将所有的证书都放入下载存储\受信任的根证书颁发机构`

View File

@ -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" // dnsipip
},
"Lookup": { // ip
"IPAddressComProvider": {