diff --git a/FastGithub.PacketIntercept/Dns/DnsInterceptor.cs b/FastGithub.PacketIntercept/Dns/DnsInterceptor.cs index b5cf13a..dda6a2c 100644 --- a/FastGithub.PacketIntercept/Dns/DnsInterceptor.cs +++ b/FastGithub.PacketIntercept/Dns/DnsInterceptor.cs @@ -22,7 +22,7 @@ namespace FastGithub.PacketIntercept.Dns [SupportedOSPlatform("windows")] 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 ILogger logger; @@ -129,7 +129,7 @@ namespace FastGithub.PacketIntercept.Dns } var question = request.Questions.First(); - if (question.Type != RecordType.A) + if (question.Type != RecordType.A && question.Type != RecordType.AAAA) { return; } @@ -142,8 +142,11 @@ namespace FastGithub.PacketIntercept.Dns // dns响应数据 var response = Response.FromRequest(request); - var record = new IPAddressResourceRecord(domain, IPAddress.Loopback, this.ttl); - response.AnswerRecords.Add(record); + if (question.Type == RecordType.A) + { + var record = new IPAddressResourceRecord(domain, IPAddress.Loopback, this.ttl); + response.AnswerRecords.Add(record); + } var responsePayload = response.ToArray(); // 修改payload和包长 @@ -151,10 +154,21 @@ namespace FastGithub.PacketIntercept.Dns packetLength = (uint)((int)packetLength + responsePayload.Length - requestPayload.Length); // 修改ip包 - var destAddress = packet.IPv4Header->DstAddr; - packet.IPv4Header->DstAddr = packet.IPv4Header->SrcAddr; - packet.IPv4Header->SrcAddr = destAddress; - packet.IPv4Header->Length = (ushort)packetLength; + IPAddress destAddress; + if (packet.IPv4Header != null) + { + 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包 var destPort = packet.UdpHeader->DstPort; diff --git a/FastGithub.UI/FlowChart.xaml.cs b/FastGithub.UI/FlowChart.xaml.cs index e1dc7a6..3fb8bc7 100644 --- a/FastGithub.UI/FlowChart.xaml.cs +++ b/FastGithub.UI/FlowChart.xaml.cs @@ -31,7 +31,7 @@ namespace FastGithub.UI public List Labels { get; } = new List(); - public Func YFormatter { get; } = value => $"{value:0.00}KB/s"; + public Func YFormatter { get; } = value => $"{FlowRate.ToNetworkSizeString((long)value)}/s"; public FlowChart() { @@ -69,11 +69,11 @@ namespace FastGithub.UI var json = await response.EnsureSuccessStatusCode().Content.ReadAsStringAsync(); var flowRate = Newtonsoft.Json.JsonConvert.DeserializeObject(json); - this.textBlockRead.Text = flowRate.ToTotalReadString(); - this.textBlockWrite.Text = flowRate.ToTotalWriteString(); + this.textBlockRead.Text = FlowRate.ToNetworkSizeString(flowRate.TotalRead); + this.textBlockWrite.Text = FlowRate.ToNetworkSizeString(flowRate.TotalWrite); - this.readSeries.Values.Add(flowRate.ReadRate / 1024); - this.writeSeries.Values.Add(flowRate.WriteRate / 1024); + this.readSeries.Values.Add(flowRate.ReadRate); + this.writeSeries.Values.Add(flowRate.WriteRate); this.Labels.Add(DateTime.Now.ToString("HH:mm:ss")); if (this.Labels.Count > 60) diff --git a/FastGithub.UI/FlowRate.cs b/FastGithub.UI/FlowRate.cs index c20c454..df1cf14 100644 --- a/FastGithub.UI/FlowRate.cs +++ b/FastGithub.UI/FlowRate.cs @@ -14,19 +14,10 @@ public double ReadRate { get; set; } - public double WriteRate { get; set; } - + public double WriteRate { get; set; } + - public string ToTotalReadString() - { - return ToNetworkString(this.TotalRead); - } - - public string ToTotalWriteString() - { - return ToNetworkString(this.TotalWrite); - } - private static string ToNetworkString(long value) + public static string ToNetworkSizeString(long value) { if (value < 1024) {