Initial commit
v1.0
This commit is contained in:
51
HSUCO_CCTV_Monitoring/StatusChecker.cs
Normal file
51
HSUCO_CCTV_Monitoring/StatusChecker.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using System;
|
||||
using System.Diagnostics.Tracing;
|
||||
using System.Net.NetworkInformation;
|
||||
using System.Text;
|
||||
|
||||
namespace HSUCO_Server_Monitoring
|
||||
{
|
||||
public class StatusChecker
|
||||
{
|
||||
public StatusResult Check(string ip)
|
||||
{
|
||||
try
|
||||
{
|
||||
Ping ping = new Ping();
|
||||
PingOptions options = new PingOptions();
|
||||
options.DontFragment = true;
|
||||
string data = "hsuco";
|
||||
byte[] buffer = ASCIIEncoding.ASCII.GetBytes(data);
|
||||
int timeout = 120;
|
||||
const int repetCount = 5;
|
||||
|
||||
int successCount = 0;
|
||||
for (int i = 0; i < repetCount; i++)
|
||||
{
|
||||
var reply = ping.Send(System.Net.IPAddress.Parse(ip), timeout, buffer, options);
|
||||
if (reply.Status == IPStatus.Success)
|
||||
{
|
||||
successCount++;
|
||||
}
|
||||
|
||||
}
|
||||
int marginal = (int)(repetCount * 0.6);
|
||||
if (successCount >= marginal)
|
||||
{
|
||||
return StatusResult.Success;
|
||||
}
|
||||
if (successCount == 0)
|
||||
{
|
||||
return StatusResult.Fail;
|
||||
}
|
||||
return StatusResult.Inspection;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Log.FATAL(ex.Message);
|
||||
return StatusResult.Fail;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user