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

Commit

Permalink
update NwAdapterTest (SDUQD-SNA#8)
Browse files Browse the repository at this point in the history
updated NwAdapterTest
removed SystemGatewayTest
  • Loading branch information
ICONQUESTION authored Dec 11, 2023
1 parent 431d659 commit 5cf52df
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 74 deletions.
1 change: 0 additions & 1 deletion SduNetCheckTool.Core/SduNetCheckTool.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@
<Compile Include="Tests\NetworkAdapterTest.cs" />
<Compile Include="Tests\SduNetTest.cs" />
<Compile Include="Tests\SduWebsiteTest.cs" />
<Compile Include="Tests\SystemGatewayTest.cs" />
<Compile Include="Tests\SystemProxyTest.cs" />
<Compile Include="Tests\TestResult.cs" />
<Compile Include="Utils\HttpUtil.cs" />
Expand Down
57 changes: 40 additions & 17 deletions SduNetCheckTool.Core/Tests/NetworkAdapterTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using SduNetCheckTool.Core.Repairs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.NetworkInformation;

namespace SduNetCheckTool.Core.Tests
Expand All @@ -12,25 +14,46 @@ public Tuple<TestResult, string, IRepair> Test()
var retList = new List<string>();
var hasNetConnection = false;

NetworkInterface[] networkInterfaces = NetworkInterface.GetAllNetworkInterfaces();

foreach (NetworkInterface networkInterface in networkInterfaces)
foreach (NetworkInterface networkInterface in NetworkInterface.GetAllNetworkInterfaces())
{
if (networkInterface.OperationalStatus == OperationalStatus.Up)
if (networkInterface.NetworkInterfaceType != NetworkInterfaceType.Loopback)
{
var ipProperties = networkInterface.GetIPProperties();
var dnsAddresses = ipProperties.DnsAddresses;

retList.Add($"网络名称: {networkInterface.Name}");
retList.Add($"网卡描述: {networkInterface.Description}");
retList.Add($"MAC地址: {networkInterface.GetPhysicalAddress()}");
retList.Add($"网卡类型: {networkInterface.NetworkInterfaceType}");
retList.Add($"网卡速度: {(networkInterface.Speed / 1000 / 1000)} Mbps");
retList.Add($"网络连接状态: {networkInterface.OperationalStatus}");
retList.Add($"DNS服务器地址: {string.Join(" ", dnsAddresses)}");
retList.Add("————————————————————————————");
if (!hasNetConnection && networkInterface.NetworkInterfaceType != NetworkInterfaceType.Loopback)
hasNetConnection = true;
IPInterfaceProperties iPInterfaceProperties = networkInterface.GetIPProperties();

var test = networkInterface.GetIPProperties();

string macInfo = networkInterface.GetPhysicalAddress().ToString() != "" ? networkInterface.GetPhysicalAddress().ToString() : "--";
string connectionSpeed = networkInterface.OperationalStatus.ToString() == "Up" ? (networkInterface.Speed / 1000 / 1000).ToString() + " Mbps" : "--";
string dhcpServers = iPInterfaceProperties.DhcpServerAddresses.Count() > 0 ? string.Join(" ", iPInterfaceProperties.DhcpServerAddresses) : "--";

retList.Add($"网络名称: {networkInterface.Name}");
retList.Add($"网卡描述: {networkInterface.Description}");
retList.Add($"MAC地址: {macInfo}");
// retList.Add($"网卡类型: {networkInterface.NetworkInterfaceType}");
retList.Add($"连接状态: {networkInterface.OperationalStatus}");
retList.Add($"连接速度: {connectionSpeed}");
retList.Add($"DNS服务器: {string.Join(" ", iPInterfaceProperties.DnsAddresses)}");
retList.Add($"DHCP服务器: {dhcpServers}");

foreach(var item in iPInterfaceProperties.UnicastAddresses)
{
retList.Add($"IP地址: {item.Address}");
}

foreach (var item in iPInterfaceProperties.GatewayAddresses)
{
retList.Add($"网关地址: {item.Address}");

Ping ping = new Ping();
PingReply reply = ping.Send(item.Address, 200);

string delay = reply.Status == IPStatus.Success ? reply.RoundtripTime.ToString() + " ms" : "--";
retList.Add($"网关延迟: {delay}");
}

retList.Add("");

hasNetConnection = true;
}
}

Expand Down
55 changes: 0 additions & 55 deletions SduNetCheckTool.Core/Tests/SystemGatewayTest.cs

This file was deleted.

1 change: 0 additions & 1 deletion SduNetCheckTool.GUI/ViewModels/TestViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ private void Init()
new DetectionTask(new NetworkAdapterTest(),"网卡检测"),
new DetectionTask(new SduNetTest(),"校园网状态检测"),
new DetectionTask(new SystemProxyTest(),"系统代理检测"),
new DetectionTask(new SystemGatewayTest(),"系统网关检测"),
new DetectionTask(new SduWebsiteTest(),"山大网站连通性检测"),
new DetectionTask(new CommonWebsiteTest(),"常用网站检测")
};
Expand Down

0 comments on commit 5cf52df

Please sign in to comment.