Skip to content
This repository has been archived by the owner on Feb 29, 2024. It is now read-only.

Commit

Permalink
Merge branch 'SDUQD-SNA:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenway authored Dec 7, 2023
2 parents 65e476e + edc9433 commit 69b50b7
Show file tree
Hide file tree
Showing 11 changed files with 191 additions and 24 deletions.
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,23 @@
- [x] 网关检测
- [x] 校内网站检测
- [x] 指定IP检测 && 路由跟踪
- [ ] 一键修复
- [x] 一键修复
- [x] 常用网站检测

## 引用的库

||开源协议|
|:---:|:---:|
|CommunityToolkit.Mvvm|MIT|
|Microsoft.Extensions.DependencyInjection|MIT|
|ModernWpfUI|MIT|
|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
5 changes: 3 additions & 2 deletions SduNetCheckTool.Core/Repairs/ProxyRepair.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,17 @@ public class ProxyRepair : IRepair
{
public Tuple<RepairResult, string> 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, string>(RepairResult.Failed, ex.Message);
}
return new Tuple<RepairResult, string>(RepairResult.Success, "已经尝试关闭系统代理,此操作并不会关闭你的代理软件!");
return new Tuple<RepairResult, string>(RepairResult.Success, "已经尝试关闭系统全局代理和PAC代理,此操作并不会关闭你的代理软件!");
}

private enum RET_ERRORS : int
Expand Down
1 change: 1 addition & 0 deletions SduNetCheckTool.Core/SduNetCheckTool.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
<Compile Include="Repairs\RepairResult.cs" />
<Compile Include="Repairs\IRepair.cs" />
<Compile Include="Repairs\DhcpRepair.cs" />
<Compile Include="Tests\CommonWebsiteTest.cs" />
<Compile Include="Tests\ITest.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Tests\NetworkAdapterTest.cs" />
Expand Down
58 changes: 58 additions & 0 deletions SduNetCheckTool.Core/Tests/CommonWebsiteTest.cs
Original file line number Diff line number Diff line change
@@ -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<TestResult, string, IRepair> Test()
{
var sduWebsites = new Dictionary<string, string>
{
{
"必应", "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<string>();
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<TestResult, string, IRepair>(result, string.Join("\n", retList), null);
}
}
}
12 changes: 9 additions & 3 deletions SduNetCheckTool.Core/Tests/SduWebsiteTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using SduNetCheckTool.Core.Utils;
using System;
using System.Collections.Generic;
using System.Net.NetworkInformation;

namespace SduNetCheckTool.Core.Tests
{
Expand All @@ -20,13 +21,18 @@ public Tuple<TestResult, string, IRepair> 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;
}

Expand Down
16 changes: 9 additions & 7 deletions SduNetCheckTool.Core/Tests/SystemGatewayTest.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -24,21 +26,21 @@ public Tuple<TestResult, string, IRepair> 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;
Expand All @@ -47,7 +49,7 @@ public Tuple<TestResult, string, IRepair> Test()
{
//ignored
}
return new Tuple<TestResult, string, IRepair>(result,string.Join("\n",data), null);
return new Tuple<TestResult, string, IRepair>(result, string.Join("\n", data), null);
}
}
}
15 changes: 11 additions & 4 deletions SduNetCheckTool.Core/Tests/SystemProxyTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ public class SystemProxyTest : ITest
public Tuple<TestResult, string, IRepair> Test()
{
var data = new List<string>();
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");
Expand All @@ -22,7 +24,7 @@ public Tuple<TestResult, string, IRepair> Test()
break;
case "0":
proxyEnabledString = "关闭";
result = TestResult.Success;
commonProxyEnabledResult = TestResult.Success;
break;
case "-1":
proxyEnabledString = "获取失败";
Expand All @@ -32,13 +34,18 @@ public Tuple<TestResult, string, IRepair> 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<TestResult, string, IRepair>(result,string.Join("\n",data), new ProxyRepair());
return new Tuple<TestResult, string, IRepair>((commonProxyEnabledResult == TestResult.Success) && (pacProxyEnabledResult == TestResult.Success) ? TestResult.Success : TestResult.Failed, string.Join("\n", data), new ProxyRepair());
}
}
}
27 changes: 27 additions & 0 deletions SduNetCheckTool.Core/Utils/RegUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,32 @@ public static bool IsNullOrEmpty(string text)
}
return text == "null";
}

public static bool IsExisted(string path, string name)
{
RegistryKey? regKey = null;

Check warning on line 72 in SduNetCheckTool.Core/Utils/RegUtil.cs

View workflow job for this annotation

GitHub Actions / build (x64, Release)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
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;
}
}
}
5 changes: 4 additions & 1 deletion SduNetCheckTool.GUI/SduNetCheckTool.GUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@
<PackageReference Include="Microsoft.Extensions.DependencyInjection">
<Version>7.0.0</Version>
</PackageReference>
<PackageReference Include="Microsoft.Toolkit.Uwp.Notifications">
<Version>7.1.3</Version>
</PackageReference>
<PackageReference Include="ModernWpfUI">
<Version>0.9.6</Version>
</PackageReference>
Expand Down Expand Up @@ -196,4 +199,4 @@
</EmbeddedResource>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
</Project>
28 changes: 26 additions & 2 deletions SduNetCheckTool.GUI/Utils/FileUtil.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using SduNetCheckTool.GUI.Common;
using System;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
Expand All @@ -14,17 +15,40 @@ public static string ExportReport(ObservableCollection<DetectionTask> 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)

Check warning on line 47 in SduNetCheckTool.GUI/Utils/FileUtil.cs

View workflow job for this annotation

GitHub Actions / build (x64, Release)

The variable 'e' is declared but never used

Check warning on line 47 in SduNetCheckTool.GUI/Utils/FileUtil.cs

View workflow job for this annotation

GitHub Actions / build (x64, Release)

The variable 'e' is declared but never used
{
//
}
return "-1";
}
}
}
33 changes: 30 additions & 3 deletions SduNetCheckTool.GUI/ViewModels/TestViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Windows;
using System.Windows.Input;
using SduNetCheckTool.GUI.Utils;
using Microsoft.Toolkit.Uwp.Notifications;

namespace SduNetCheckTool.GUI.ViewModels
{
Expand All @@ -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<IRepair>();
}
Expand All @@ -51,7 +53,7 @@ public ObservableCollection<DetectionTask> Tasks
public ICommand StartCommand { get; }

public ICommand RepairCommand { get; }

public ICommand ExportReportCommand { get; }

private async void Repair()
Expand Down Expand Up @@ -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();
}
}
}
}
}

0 comments on commit 69b50b7

Please sign in to comment.