老九 3 years ago
parent
commit
e478f0855c

+ 22 - 8
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<DnsInterceptor> 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;

+ 5 - 5
FastGithub.UI/FlowChart.xaml.cs

@@ -31,7 +31,7 @@ namespace FastGithub.UI
 
         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()
         {
@@ -69,11 +69,11 @@ namespace FastGithub.UI
             var json = await response.EnsureSuccessStatusCode().Content.ReadAsStringAsync();
             var flowRate = Newtonsoft.Json.JsonConvert.DeserializeObject<FlowRate>(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)

+ 3 - 12
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)
             {