手动配置ip
This commit is contained in:
parent
acb18d7078
commit
6fb855f06f
@ -28,5 +28,10 @@ namespace FastGithub.Dns
|
|||||||
/// 是否使用反向代理访问github
|
/// 是否使用反向代理访问github
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool UseGithubReverseProxy { get; set; }
|
public bool UseGithubReverseProxy { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// dns响应的反向代理服务的ip
|
||||||
|
/// </summary>
|
||||||
|
public IPAddress GithubReverseProxyIPAddress { get; set; } = IPAddress.Loopback;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,8 +7,6 @@ using Microsoft.Extensions.Logging;
|
|||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
|
||||||
using System.Net.Sockets;
|
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
@ -46,20 +44,20 @@ namespace FastGithub.Dns
|
|||||||
/// <param name="request"></param>
|
/// <param name="request"></param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <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();
|
var question = request.Questions.FirstOrDefault();
|
||||||
|
|
||||||
if (question == null || question.Type != RecordType.A)
|
if (question == null || question.Type != RecordType.A)
|
||||||
{
|
{
|
||||||
return response;
|
return Task.FromResult(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
var domain = question.Name.ToString();
|
var domain = question.Name.ToString();
|
||||||
if (this.githubResolver.IsSupported(domain) == false)
|
if (this.githubResolver.IsSupported(domain) == false)
|
||||||
{
|
{
|
||||||
return response;
|
return Task.FromResult(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.options.CurrentValue.UseGithubReverseProxy == false)
|
if (this.options.CurrentValue.UseGithubReverseProxy == false)
|
||||||
@ -75,7 +73,7 @@ namespace FastGithub.Dns
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var address = await GetLocalHostAddress();
|
var address = this.options.CurrentValue.GithubReverseProxyIPAddress;
|
||||||
var record = new IPAddressResourceRecord(question.Name, address, TimeSpan.FromMinutes(1));
|
var record = new IPAddressResourceRecord(question.Name, address, TimeSpan.FromMinutes(1));
|
||||||
response.AnswerRecords.Add(record);
|
response.AnswerRecords.Add(record);
|
||||||
this.logger.LogInformation($"[{domain}->{address}]");
|
this.logger.LogInformation($"[{domain}->{address}]");
|
||||||
@ -85,26 +83,7 @@ namespace FastGithub.Dns
|
|||||||
{
|
{
|
||||||
this.logger.LogWarning($"无法获得{domain}的最快ip");
|
this.logger.LogWarning($"无法获得{domain}的最快ip");
|
||||||
}
|
}
|
||||||
return response;
|
return Task.FromResult(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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,11 +1,12 @@
|
|||||||
# FastGithub
|
# FastGithub
|
||||||
github定制版的dns服务,解析github最优的ip
|
github定制版的dns服务,解析github最优的ip
|
||||||
|
|
||||||
### 本机使用
|
### 本机使用[推荐]
|
||||||
* 运行FastGithub程序,本机的网络适配器的dns会自动变成127.0.0.1
|
* 运行FastGithub程序,本机的网络适配器的dns会自动变成127.0.0.1
|
||||||
* 如果网络适配器的dns没有变成127.0.0.1,请手工修改网络适配器的dns
|
* 如果网络适配器的dns没有变成127.0.0.1,请手工修改网络适配器的dns
|
||||||
|
|
||||||
### 局域网服务器使用
|
### 局域网服务器使用
|
||||||
|
* 修改appsettings.json文件的`Dns:GithubReverseProxyIPAddress`为局域网ip
|
||||||
* 在局域网服务器运行FastGithub程序
|
* 在局域网服务器运行FastGithub程序
|
||||||
* 手工修改你电脑的网络适配器的dns,值为局域网服务器的ip
|
* 手工修改你电脑的网络适配器的dns,值为局域网服务器的ip
|
||||||
* 在你的电脑安装FastGithub.cer到`将所有的证书都放入下载存储\受信任的根证书颁发机构`
|
* 在你的电脑安装FastGithub.cer到`将所有的证书都放入下载存储\受信任的根证书颁发机构`
|
||||||
|
|||||||
@ -3,7 +3,8 @@
|
|||||||
"UpStream": "114.114.114.114", // 上游dns
|
"UpStream": "114.114.114.114", // 上游dns
|
||||||
"GithubTTL": "00:10:00", // github相关域名解析结果的存活时长
|
"GithubTTL": "00:10:00", // github相关域名解析结果的存活时长
|
||||||
"SetToLocalMachine": true, // 是否设置本机使用此dns(仅支持windows)
|
"SetToLocalMachine": true, // 是否设置本机使用此dns(仅支持windows)
|
||||||
"UseGithubReverseProxy": true // 是否使用反向代理访问github以解决连接被重复的问题
|
"UseGithubReverseProxy": true, // 是否使用反向代理访问github以解决连接被重复的问题
|
||||||
|
"GithubReverseProxyIPAddress": "127.0.0.1" // dns响应的反向代理服务ip,局域网部署时要填写局域网ip
|
||||||
},
|
},
|
||||||
"Lookup": { // ip查找
|
"Lookup": { // ip查找
|
||||||
"IPAddressComProvider": {
|
"IPAddressComProvider": {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user