diff --git a/README.md b/README.md index 406d2aa..f2c4cdd 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,8 @@ - [x] 网关检测 - [x] 校内网站检测 - [x] 指定IP检测 && 路由跟踪 -- [ ] 一键修复 +- [x] 一键修复 +- [x] 常用网站检测 ## 引用的库 @@ -18,4 +19,14 @@ |:---:|:---:| |CommunityToolkit.Mvvm|MIT| |Microsoft.Extensions.DependencyInjection|MIT| -|ModernWpfUI|MIT| \ No newline at end of file +|ModernWpfUI|MIT| + +## CI/CD + +您可以在[Github Action](https://github.com/SDUQD-SNA/SduNetCheckTool/actions)获取最新构建的**测试**版本。 + +## 开源协议 + +本软件以[GPLv3](https://github.com/SDUQD-SNA/SduNetCheckTool/blob/master/LICENSE.txt)协议开源。 + +Copyright © 2023 SDUQD-SNA diff --git a/SduNetCheckTool.Core/Repairs/ProxyRepair.cs b/SduNetCheckTool.Core/Repairs/ProxyRepair.cs index 908e62b..267a8a1 100644 --- a/SduNetCheckTool.Core/Repairs/ProxyRepair.cs +++ b/SduNetCheckTool.Core/Repairs/ProxyRepair.cs @@ -10,16 +10,17 @@ public class ProxyRepair : IRepair { public Tuple Repair() { - RegUtil.RegWriteValue(@"Software\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyEnable", "0"); try { + RegUtil.RegWriteValue(@"Software\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyEnable", "0"); + RegUtil.RegWriteValue(@"Software\Microsoft\Windows\CurrentVersion\Internet Settings", "AutoConfigURL", ""); ResetIEProxy(); } catch (Exception ex) { return new Tuple(RepairResult.Failed, ex.Message); } - return new Tuple(RepairResult.Success, "已经尝试关闭系统代理,此操作并不会关闭你的代理软件!"); + return new Tuple(RepairResult.Success, "已经尝试关闭系统全局代理和PAC代理,此操作并不会关闭你的代理软件!"); } private enum RET_ERRORS : int diff --git a/SduNetCheckTool.Core/SduNetCheckTool.Core.csproj b/SduNetCheckTool.Core/SduNetCheckTool.Core.csproj index 3bb643f..57fee7a 100644 --- a/SduNetCheckTool.Core/SduNetCheckTool.Core.csproj +++ b/SduNetCheckTool.Core/SduNetCheckTool.Core.csproj @@ -50,6 +50,7 @@ + diff --git a/SduNetCheckTool.Core/Tests/CommonWebsiteTest.cs b/SduNetCheckTool.Core/Tests/CommonWebsiteTest.cs new file mode 100644 index 0000000..bffa47e --- /dev/null +++ b/SduNetCheckTool.Core/Tests/CommonWebsiteTest.cs @@ -0,0 +1,58 @@ +using SduNetCheckTool.Core.Repairs; +using SduNetCheckTool.Core.Utils; +using System; +using System.Collections.Generic; +using System.Net.NetworkInformation; + +namespace SduNetCheckTool.Core.Tests +{ + public class CommonWebsiteTest : ITest + { + public Tuple Test() + { + var sduWebsites = new Dictionary + { + { + "必应", "https://cn.bing.com" + }, + { + "知网", "https://www.cnki.net" + }, + { + "知乎", "https://www.zhihu.com" + }, + { + "百度", "https://www.baidu.com" + }, + { + "哔哩哔哩", "https://www.bilibili.com" + }, + { + "中国大学MOOC", "https://www.icourse163.org" + }, + }; + + var retList = new List(); + var result = TestResult.Success; + + foreach (var sduWebsite in sduWebsites) + { + var domain = new Uri(sduWebsite.Value).Host; + var ping = new Ping(); + var reply = ping.Send(domain, 2000); + + var response = HttpUtil.GetHttpResponse(sduWebsite.Value); + + if (reply.Status == IPStatus.Success && response != null) + { + retList.Add($"[ {response.StatusCode} ] {sduWebsite.Key} ( {sduWebsite.Value} ) {reply.Address} - {reply.RoundtripTime} ms"); + continue; + } + retList.Add($"{sduWebsite.Key} ( {sduWebsite.Value} ) - 无法访问"); + result = TestResult.Failed; + } + + return Tuple.Create(result, string.Join("\n", retList), null); + } + } +} diff --git a/SduNetCheckTool.Core/Tests/SduWebsiteTest.cs b/SduNetCheckTool.Core/Tests/SduWebsiteTest.cs index fe9d4ab..be3befc 100644 --- a/SduNetCheckTool.Core/Tests/SduWebsiteTest.cs +++ b/SduNetCheckTool.Core/Tests/SduWebsiteTest.cs @@ -2,6 +2,7 @@ using SduNetCheckTool.Core.Utils; using System; using System.Collections.Generic; +using System.Net.NetworkInformation; namespace SduNetCheckTool.Core.Tests { @@ -20,13 +21,18 @@ public Tuple Test() foreach (var sduWebsite in sduWebsites) { + var domain = new Uri(sduWebsite.Value).Host; + var ping = new Ping(); + var reply = ping.Send(domain, 2000); + var response = HttpUtil.GetHttpResponse(sduWebsite.Value); - if (response != null) + + if (reply.Status == IPStatus.Success && response != null) { - retList.Add($"{sduWebsite.Key}({sduWebsite.Value}) - {response.StatusCode}"); + retList.Add($"[ {response.StatusCode} ] {sduWebsite.Key} ( {sduWebsite.Value} ) {reply.Address} - {reply.RoundtripTime} ms"); continue; } - retList.Add($"{sduWebsite.Key}({sduWebsite.Value}) - 无法访问"); + retList.Add($"{sduWebsite.Key} ( {sduWebsite.Value} ) - 无法访问"); result = TestResult.Failed; } diff --git a/SduNetCheckTool.Core/Tests/SystemGatewayTest.cs b/SduNetCheckTool.Core/Tests/SystemGatewayTest.cs index 5e8c309..a5944f2 100644 --- a/SduNetCheckTool.Core/Tests/SystemGatewayTest.cs +++ b/SduNetCheckTool.Core/Tests/SystemGatewayTest.cs @@ -1,8 +1,10 @@ using SduNetCheckTool.Core.Repairs; using System; using System.Collections.Generic; +using System.Linq; using System.Net; using System.Net.NetworkInformation; +using System.Threading; namespace SduNetCheckTool.Core.Tests { @@ -24,21 +26,21 @@ public Tuple Test() IPAddressCollection addresses = iPInterfaceProperties.DhcpServerAddresses; foreach (var item in gatewayIPAddressInformation) { - data.Add($"网卡信息:......{networkInterface.Description}"); - data.Add($"网关地址:......{item.Address}"); - PingReply reply = ping.Send(item.Address); - data.Add($"是否封禁:......{(reply.Status == IPStatus.Success ? "未封禁" : "封禁")}"); + data.Add($"网卡信息: {networkInterface.Description}"); + data.Add($"网关地址: {item.Address}"); + PingReply reply = ping.Send(item.Address, 200); if (reply.Status == IPStatus.Success) { - data.Add($"网关延迟:......{reply.RoundtripTime} ms"); + data.Add($"网关延迟: {reply.RoundtripTime} ms"); } if (addresses.Count > 0) { foreach (IPAddress address in addresses) { - data.Add($"Dhcp地址:.....{address}\n"); + data.Add($"DHCP服务器: {address}"); } } + data[data.Count - 1] = data.Last() + "\n"; } } result = TestResult.Success; @@ -47,7 +49,7 @@ public Tuple Test() { //ignored } - return new Tuple(result,string.Join("\n",data), null); + return new Tuple(result, string.Join("\n", data), null); } } } diff --git a/SduNetCheckTool.Core/Tests/SystemProxyTest.cs b/SduNetCheckTool.Core/Tests/SystemProxyTest.cs index 1530233..593cd2b 100644 --- a/SduNetCheckTool.Core/Tests/SystemProxyTest.cs +++ b/SduNetCheckTool.Core/Tests/SystemProxyTest.cs @@ -10,7 +10,9 @@ public class SystemProxyTest : ITest public Tuple Test() { var data = new List(); - var result = TestResult.Failed; + var commonProxyEnabledResult = TestResult.Failed; + var pacProxyEnabledResult = TestResult.Failed; + try { var proxyEnabled = RegUtil.RegReadValue(@"Software\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyEnable", "-1"); @@ -22,7 +24,7 @@ public Tuple Test() break; case "0": proxyEnabledString = "关闭"; - result = TestResult.Success; + commonProxyEnabledResult = TestResult.Success; break; case "-1": proxyEnabledString = "获取失败"; @@ -32,13 +34,18 @@ public Tuple Test() break; } - data.Add($"代理状态:{proxyEnabledString}"); + data.Add($"系统全局代理状态: {proxyEnabledString}"); + + var PACproxyEnabledString = (RegUtil.IsExisted(@"Software\Microsoft\Windows\CurrentVersion\Internet Settings", "AutoConfigURL") ? "开启" : "关闭"); + if (PACproxyEnabledString == "关闭") pacProxyEnabledResult = TestResult.Success; + + data.Add($"PAC代理状态: {PACproxyEnabledString}"); } catch (Exception) { //ignored } - return new Tuple(result,string.Join("\n",data), new ProxyRepair()); + return new Tuple((commonProxyEnabledResult == TestResult.Success) && (pacProxyEnabledResult == TestResult.Success) ? TestResult.Success : TestResult.Failed, string.Join("\n", data), new ProxyRepair()); } } } diff --git a/SduNetCheckTool.Core/Utils/RegUtil.cs b/SduNetCheckTool.Core/Utils/RegUtil.cs index 85299e4..075fdf9 100644 --- a/SduNetCheckTool.Core/Utils/RegUtil.cs +++ b/SduNetCheckTool.Core/Utils/RegUtil.cs @@ -66,5 +66,32 @@ public static bool IsNullOrEmpty(string text) } return text == "null"; } + + public static bool IsExisted(string path, string name) + { + RegistryKey? regKey = null; + var isExisted = false; + try + { + regKey = Registry.CurrentUser.OpenSubKey(path); + string[] subkeyNames = regKey.GetValueNames(); + foreach (string keyname in subkeyNames) + { + if (keyname == name) + { + isExisted = true; + } + } + } + catch (Exception ex) + { + Debug.WriteLine(ex.Message); + } + finally + { + regKey?.Close(); + } + return isExisted; + } } } diff --git a/SduNetCheckTool.GUI/SduNetCheckTool.GUI.csproj b/SduNetCheckTool.GUI/SduNetCheckTool.GUI.csproj index 8219bce..5ad2866 100644 --- a/SduNetCheckTool.GUI/SduNetCheckTool.GUI.csproj +++ b/SduNetCheckTool.GUI/SduNetCheckTool.GUI.csproj @@ -168,6 +168,9 @@ 7.0.0 + + 7.1.3 + 0.9.6 @@ -196,4 +199,4 @@ - + \ No newline at end of file diff --git a/SduNetCheckTool.GUI/Utils/FileUtil.cs b/SduNetCheckTool.GUI/Utils/FileUtil.cs index cdd3097..7c01b8e 100644 --- a/SduNetCheckTool.GUI/Utils/FileUtil.cs +++ b/SduNetCheckTool.GUI/Utils/FileUtil.cs @@ -1,4 +1,5 @@ using SduNetCheckTool.GUI.Common; +using System; using System.Collections.ObjectModel; using System.IO; using System.Linq; @@ -14,17 +15,40 @@ public static string ExportReport(ObservableCollection tasks) var exportFilePath = ExportPath + "\\" + System.DateTime.Now.ToString("yyyy-MM-dd-hh-mm-ss") + ".txt"; if (tasks.Any(i => i.TaskStatusEnum == TaskStatusEnum.Waiting)) - return "请先运行测试"; + return "NoRecords"; if (!Directory.Exists(ExportPath)) Directory.CreateDirectory(ExportPath); foreach (var detectionTask in tasks) { - File.AppendAllText(exportFilePath, detectionTask.Tips + '\n', Encoding.UTF8); + File.AppendAllText(exportFilePath, detectionTask.Tips + '\n' + '\n', Encoding.UTF8); } return exportFilePath; } + + public static string ReadFile(string filePath) + { + if (!File.Exists(filePath)) return "FileNotExists"; + + try + { + StreamReader sr = new StreamReader(filePath); + string data = "", line = ""; + + while ((line = sr.ReadLine()) != null) + { + data += line + "\n"; + } + + return data; + } + catch (Exception e) + { + // + } + return "-1"; + } } } diff --git a/SduNetCheckTool.GUI/ViewModels/TestViewModel.cs b/SduNetCheckTool.GUI/ViewModels/TestViewModel.cs index fdcd81c..9fd3e5a 100644 --- a/SduNetCheckTool.GUI/ViewModels/TestViewModel.cs +++ b/SduNetCheckTool.GUI/ViewModels/TestViewModel.cs @@ -9,6 +9,7 @@ using System.Windows; using System.Windows.Input; using SduNetCheckTool.GUI.Utils; +using Microsoft.Toolkit.Uwp.Notifications; namespace SduNetCheckTool.GUI.ViewModels { @@ -30,7 +31,8 @@ private void Init() new DetectionTask(new SduNetTest(),"校园网状态检测"), new DetectionTask(new SystemProxyTest(),"系统代理检测"), new DetectionTask(new SystemGatewayTest(),"系统网关检测"), - new DetectionTask(new SduWebsiteTest(),"山大网站连通性检测") + new DetectionTask(new SduWebsiteTest(),"山大网站连通性检测"), + new DetectionTask(new CommonWebsiteTest(),"常用网站检测") }; _repairs = new Collection(); } @@ -51,7 +53,7 @@ public ObservableCollection Tasks public ICommand StartCommand { get; } public ICommand RepairCommand { get; } - + public ICommand ExportReportCommand { get; } private async void Repair() @@ -91,7 +93,32 @@ await Task.Run(() => private void ExportReport() { - MessageBox.Show("日志文件导出:" + FileUtil.ExportReport(Tasks)); + var output = FileUtil.ExportReport(Tasks); + if (output == "NoRecords") + { + MessageBox.Show("请先点击'开始检测'运行测试! >_<", "提示"); + } + else + { + MessageBoxResult result = MessageBox.Show("日志文件已生成! (⑅•ᴗ•⑅) \n路径: " + output + "\n点击'确定'打开日志并自动复制到剪贴板!", "提示"); + if (result == MessageBoxResult.OK) + { + System.Diagnostics.Process.Start(output); + string data = FileUtil.ReadFile(output); + if (data == "FileNotExists" || data == "-1") + { + MessageBox.Show("出现了一点小错误..."); + return; + } + Clipboard.SetText(data); + new ToastContentBuilder() + .AddArgument("action", "viewConversation") + .AddArgument("conversationId", 9813) + .AddText("已经成功复制内容到剪贴板啦! ๐•ᴗ•๐") + .AddText("可以直接分享给同学哦~") + .Show(); + } + } } } }