IPv6 dns
This commit is contained in:
parent
977694eaa8
commit
e478f0855c
@ -22,7 +22,7 @@ namespace FastGithub.PacketIntercept.Dns
|
|||||||
[SupportedOSPlatform("windows")]
|
[SupportedOSPlatform("windows")]
|
||||||
sealed class DnsInterceptor : IDnsInterceptor
|
sealed class DnsInterceptor : IDnsInterceptor
|
||||||
{
|
{
|
||||||
private const string DNS_FILTER = "ip and udp.DstPort == 53";
|
private const string DNS_FILTER = "udp.DstPort == 53";
|
||||||
|
|
||||||
private readonly FastGithubConfig fastGithubConfig;
|
private readonly FastGithubConfig fastGithubConfig;
|
||||||
private readonly ILogger<DnsInterceptor> logger;
|
private readonly ILogger<DnsInterceptor> logger;
|
||||||
@ -129,7 +129,7 @@ namespace FastGithub.PacketIntercept.Dns
|
|||||||
}
|
}
|
||||||
|
|
||||||
var question = request.Questions.First();
|
var question = request.Questions.First();
|
||||||
if (question.Type != RecordType.A)
|
if (question.Type != RecordType.A && question.Type != RecordType.AAAA)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -142,8 +142,11 @@ namespace FastGithub.PacketIntercept.Dns
|
|||||||
|
|
||||||
// dns响应数据
|
// dns响应数据
|
||||||
var response = Response.FromRequest(request);
|
var response = Response.FromRequest(request);
|
||||||
var record = new IPAddressResourceRecord(domain, IPAddress.Loopback, this.ttl);
|
if (question.Type == RecordType.A)
|
||||||
response.AnswerRecords.Add(record);
|
{
|
||||||
|
var record = new IPAddressResourceRecord(domain, IPAddress.Loopback, this.ttl);
|
||||||
|
response.AnswerRecords.Add(record);
|
||||||
|
}
|
||||||
var responsePayload = response.ToArray();
|
var responsePayload = response.ToArray();
|
||||||
|
|
||||||
// 修改payload和包长
|
// 修改payload和包长
|
||||||
@ -151,10 +154,21 @@ namespace FastGithub.PacketIntercept.Dns
|
|||||||
packetLength = (uint)((int)packetLength + responsePayload.Length - requestPayload.Length);
|
packetLength = (uint)((int)packetLength + responsePayload.Length - requestPayload.Length);
|
||||||
|
|
||||||
// 修改ip包
|
// 修改ip包
|
||||||
var destAddress = packet.IPv4Header->DstAddr;
|
IPAddress destAddress;
|
||||||
packet.IPv4Header->DstAddr = packet.IPv4Header->SrcAddr;
|
if (packet.IPv4Header != null)
|
||||||
packet.IPv4Header->SrcAddr = destAddress;
|
{
|
||||||
packet.IPv4Header->Length = (ushort)packetLength;
|
destAddress = packet.IPv4Header->DstAddr;
|
||||||
|
packet.IPv4Header->DstAddr = packet.IPv4Header->SrcAddr;
|
||||||
|
packet.IPv4Header->SrcAddr = destAddress;
|
||||||
|
packet.IPv4Header->Length = (ushort)packetLength;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
destAddress = packet.IPv6Header->DstAddr;
|
||||||
|
packet.IPv6Header->DstAddr = packet.IPv6Header->SrcAddr;
|
||||||
|
packet.IPv6Header->SrcAddr = destAddress;
|
||||||
|
packet.IPv6Header->Length = (ushort)packetLength;
|
||||||
|
}
|
||||||
|
|
||||||
// 修改udp包
|
// 修改udp包
|
||||||
var destPort = packet.UdpHeader->DstPort;
|
var destPort = packet.UdpHeader->DstPort;
|
||||||
|
|||||||
@ -31,7 +31,7 @@ namespace FastGithub.UI
|
|||||||
|
|
||||||
public List<string> Labels { get; } = new List<string>();
|
public List<string> Labels { get; } = new List<string>();
|
||||||
|
|
||||||
public Func<double, string> YFormatter { get; } = value => $"{value:0.00}KB/s";
|
public Func<double, string> YFormatter { get; } = value => $"{FlowRate.ToNetworkSizeString((long)value)}/s";
|
||||||
|
|
||||||
public FlowChart()
|
public FlowChart()
|
||||||
{
|
{
|
||||||
@ -69,11 +69,11 @@ namespace FastGithub.UI
|
|||||||
var json = await response.EnsureSuccessStatusCode().Content.ReadAsStringAsync();
|
var json = await response.EnsureSuccessStatusCode().Content.ReadAsStringAsync();
|
||||||
var flowRate = Newtonsoft.Json.JsonConvert.DeserializeObject<FlowRate>(json);
|
var flowRate = Newtonsoft.Json.JsonConvert.DeserializeObject<FlowRate>(json);
|
||||||
|
|
||||||
this.textBlockRead.Text = flowRate.ToTotalReadString();
|
this.textBlockRead.Text = FlowRate.ToNetworkSizeString(flowRate.TotalRead);
|
||||||
this.textBlockWrite.Text = flowRate.ToTotalWriteString();
|
this.textBlockWrite.Text = FlowRate.ToNetworkSizeString(flowRate.TotalWrite);
|
||||||
|
|
||||||
this.readSeries.Values.Add(flowRate.ReadRate / 1024);
|
this.readSeries.Values.Add(flowRate.ReadRate);
|
||||||
this.writeSeries.Values.Add(flowRate.WriteRate / 1024);
|
this.writeSeries.Values.Add(flowRate.WriteRate);
|
||||||
this.Labels.Add(DateTime.Now.ToString("HH:mm:ss"));
|
this.Labels.Add(DateTime.Now.ToString("HH:mm:ss"));
|
||||||
|
|
||||||
if (this.Labels.Count > 60)
|
if (this.Labels.Count > 60)
|
||||||
|
|||||||
@ -14,19 +14,10 @@
|
|||||||
|
|
||||||
public double ReadRate { get; set; }
|
public double ReadRate { get; set; }
|
||||||
|
|
||||||
public double WriteRate { get; set; }
|
public double WriteRate { get; set; }
|
||||||
|
|
||||||
|
|
||||||
public string ToTotalReadString()
|
public static string ToNetworkSizeString(long value)
|
||||||
{
|
|
||||||
return ToNetworkString(this.TotalRead);
|
|
||||||
}
|
|
||||||
|
|
||||||
public string ToTotalWriteString()
|
|
||||||
{
|
|
||||||
return ToNetworkString(this.TotalWrite);
|
|
||||||
}
|
|
||||||
private static string ToNetworkString(long value)
|
|
||||||
{
|
{
|
||||||
if (value < 1024)
|
if (value < 1024)
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user