-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPingResults.cs
59 lines (51 loc) · 1.67 KB
/
PingResults.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Net.NetworkInformation;
namespace DotoPing2
{
class PingResults
{
public string PingAddress;
public string ServerName;
List<int> lPingResults = new List<int>();
private int avgPing;
private int jitPing;
private int totalPings;
private long lastPing;
// Encapsulate return
public long LastPing { get { return lastPing; } }
public int AvgPing { get { return avgPing; } }
public int JitPing { get { return jitPing; } }
public int TotalPings { get { return totalPings; } }
// Calculate Standard Deviation
public void StandardDeviation()
{
avgPing = (int) lPingResults.Average();
jitPing = (int) Math.Sqrt(lPingResults.Average(v => Math.Pow(v - AvgPing, 2)));
}
// Perform Ping, duh. Timer set to stagger ping return
public void DoPing()
{
totalPings = 0;
Ping newPing = new Ping();
for (int i = 1; i < 5000; i++)
{
PingReply reply = newPing.Send(PingAddress);
if (reply.Status == IPStatus.Success)
{
Task.Delay(2800).Wait();
lastPing = (int) reply.RoundtripTime;
lPingResults.Add((int) LastPing);
StandardDeviation();
totalPings++;
}
else
{
lastPing = 999;
}
}
}
}
}