📄 gatewaydetectaction.cs
字号:
namespace Imps.Client.CommLayer.NetworkDetect
{
using Imps.Client.Resource;
using Imps.Client.Utils;
using System;
using System.Collections.Generic;
using System.Net.NetworkInformation;
using System.Threading;
public class GateWayDetectAction : DetectAction
{
private Ping _ping;
public GateWayDetectAction()
{
base.Description = "网关";
base.NextStage = NetworkDetectStage.IeOffline;
this._ping = new Ping();
}
public override void BeginDetectAction()
{
ThreadPool.QueueUserWorkItem(new WaitCallback(this.StartDetect), this);
}
public override void CancelDetectAction()
{
}
private void StartDetect(object state)
{
Thread.CurrentThread.Name = "Imps.Client.Pc.NetworkDetect.GateWayDetectAction";
List<DetectResult> details = new List<DetectResult>();
Queue<GatewayIPAddressInformation> gateways = new Queue<GatewayIPAddressInformation>();
try
{
foreach (NetworkInterface interface2 in NetworkInterface.GetAllNetworkInterfaces())
{
using (IEnumerator<GatewayIPAddressInformation> enumerator = interface2.GetIPProperties().get_GatewayAddresses().GetEnumerator())
{
while (enumerator.MoveNext())
{
GatewayIPAddressInformation information = enumerator.get_Current();
gateways.Enqueue(information);
}
}
}
if (gateways.get_Count() > 0)
{
this.TestGateWay(gateways, details);
}
else
{
details.Add(new DetectResult(DetectStatus.Suspect, StringTable.NetworkDetect.NoGateWay));
base.CanResume = true;
base.FireDetecFinsihedEvent(this, new DetectEventArgs(true, details));
}
}
catch (PlatformNotSupportedException exception)
{
ClientLogger.WriteGeneral(exception.ToString());
details.Add(new DetectResult(DetectStatus.Failed, StringTable.NetworkDetect.PlatformNotSupport));
base.CanResume = true;
base.FireDetecFinsihedEvent(this, new DetectEventArgs(false, details));
}
catch (Exception exception2)
{
ClientLogger.WriteGeneral(exception2.ToString());
details.Add(new DetectResult(DetectStatus.Failed, StringTable.NetworkDetect.ErrorOccour));
base.CanResume = true;
base.FireDetecFinsihedEvent(this, new DetectEventArgs(false, details));
}
}
private void TestGateWay(Queue<GatewayIPAddressInformation> gateways, List<DetectResult> details)
{
int num = 0;
while (gateways.get_Count() > 0)
{
string description = gateways.Dequeue().get_Address().ToString();
try
{
if (description.StartsWith("169"))
{
details.Add(new DetectResult(DetectStatus.Failed, description));
num++;
}
else if (this._ping.Send(description, 0x3e8).get_Status() == null)
{
details.Add(new DetectResult(DetectStatus.Passed, description));
}
else
{
details.Add(new DetectResult(DetectStatus.Failed, description));
num++;
}
continue;
}
catch (Exception exception)
{
ClientLogger.WriteGeneral(exception.ToString());
details.Add(new DetectResult(DetectStatus.Failed, description));
continue;
}
}
base.CanResume = true;
base.FireDetecFinsihedEvent(this, new DetectEventArgs(num == 0, details));
}
public override NetworkDetectStage CurrentStage
{
get
{
return NetworkDetectStage.GateWay;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -