Repository navigation
Expand file tree
/
Copy pathPingInfo.cs
More file actions
182 lines (165 loc) · 6.73 KB
/
Copy pathPingInfo.cs
File metadata and controls
182 lines (165 loc) · 6.73 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
using System;
using System.Net;
using System.Net.NetworkInformation;
using System.Net.Sockets;
namespace NETworkManager.Models.Network;
/// <summary>
/// Class containing the information of a ping.
/// </summary>
public class PingInfo
{
/// <summary>
/// Creates a new instance of <see cref="PingInfo" />.
/// </summary>
public PingInfo()
{
}
/// <summary>
/// Creates a new instance of <see cref="PingInfo" /> with the specified parameters.
/// </summary>
/// <param name="timestamp">Timestamp when the ping was sent.</param>
/// <param name="ipAddress">IP address of the host.</param>
/// <param name="status">IP status of the ping.</param>
public PingInfo(DateTime timestamp, IPAddress ipAddress, IPStatus status)
{
Timestamp = timestamp;
IPAddress = ipAddress;
Status = status;
}
/// <summary>
/// Creates a new instance of <see cref="PingInfo" /> with the specified parameters.
/// </summary>
/// <param name="timestamp">Timestamp when the ping was sent.</param>
/// <param name="ipAddress">IP address of the host.</param>
/// <param name="hostname">Hostname of the host.</param>
/// <param name="status">IP status of the ping.</param>
public PingInfo(DateTime timestamp, IPAddress ipAddress, string hostname, IPStatus status)
{
Timestamp = timestamp;
IPAddress = ipAddress;
Hostname = hostname;
Status = status;
}
/// <summary>
/// Creates a new instance of <see cref="PingInfo" /> with the specified parameters.
/// </summary>
/// <param name="timestamp">Timestamp when the ping was sent.</param>
/// <param name="ipAddress">IP address of the host.</param>
/// <param name="bytes">Bytes used to send the icmp packet.</param>
/// <param name="time">Time in milliseconds how long it took to receive a response.</param>
/// <param name="status">IP status of the ping.</param>
public PingInfo(DateTime timestamp, IPAddress ipAddress, int bytes, long time, IPStatus status)
{
Timestamp = timestamp;
IPAddress = ipAddress;
Bytes = bytes;
Time = time;
Status = status;
}
/// <summary>
/// Creates a new instance of <see cref="PingInfo" /> with the specified parameters.
/// </summary>
/// <param name="timestamp">Timestamp when the ping was sent.</param>
/// <param name="ipAddress">IP address of the host.</param>
/// <param name="hostname">Hostname of the host.</param>
/// <param name="bytes">Bytes used to send the icmp packet.</param>
/// <param name="time">Time in milliseconds how long it took to receive a response.</param>
/// <param name="status">IP status of the ping.</param>
public PingInfo(DateTime timestamp, IPAddress ipAddress, string hostname, int bytes, long time, IPStatus status)
{
Timestamp = timestamp;
IPAddress = ipAddress;
Hostname = hostname;
Bytes = bytes;
Time = time;
Status = status;
}
/// <summary>
/// Creates a new instance of <see cref="PingInfo" /> with the specified parameters.
/// </summary>
/// <param name="timestamp">Timestamp when the ping was sent.</param>
/// <param name="ipAddress">IP address of the host.</param>
/// <param name="bytes">Bytes used to send the icmp packet.</param>
/// <param name="time">Time in milliseconds how long it took to receive a response.</param>
/// <param name="ttl">Time to live of the icmp packet.</param>
/// <param name="status">IP status of the ping.</param>
public PingInfo(DateTime timestamp, IPAddress ipAddress, int bytes, long time, int ttl, IPStatus status)
{
Timestamp = timestamp;
IPAddress = ipAddress;
Bytes = bytes;
Time = time;
TTL = ttl;
Status = status;
}
/// <summary>
/// Creates a new instance of <see cref="PingInfo" /> with the specified parameters.
/// </summary>
/// <param name="timestamp">Timestamp when the ping was sent.</param>
/// <param name="ipAddress">IP address of the host.</param>
/// <param name="hostname">Hostname of the host.</param>
/// <param name="bytes">Bytes used to send the icmp packet.</param>
/// <param name="time">Time in milliseconds how long it took to receive a response.</param>
/// <param name="ttl">Time to live of the icmp packet.</param>
/// <param name="status">IP status of the ping.</param>
public PingInfo(DateTime timestamp, IPAddress ipAddress, string hostname, int bytes, long time, int ttl,
IPStatus status)
{
Timestamp = timestamp;
IPAddress = ipAddress;
Hostname = hostname;
Bytes = bytes;
Time = time;
TTL = ttl;
Status = status;
}
/// <summary>
/// Creates a <see cref="PingInfo" /> from a successful ping reply. The TTL is only available for IPv4.
/// </summary>
/// <param name="timestamp">Timestamp when the ping was sent.</param>
/// <param name="pingReply">Successful reply of the ping.</param>
/// <param name="hostname">Hostname of the host.</param>
/// <returns>Information of the ping.</returns>
internal static PingInfo FromSuccessfulReply(DateTime timestamp, PingReply pingReply, string hostname = null)
{
return pingReply.Address.AddressFamily == AddressFamily.InterNetwork
? new PingInfo(timestamp, pingReply.Address, hostname, pingReply.Buffer.Length, pingReply.RoundtripTime,
pingReply.Options!.Ttl, pingReply.Status)
: new PingInfo(timestamp, pingReply.Address, hostname, pingReply.Buffer.Length, pingReply.RoundtripTime,
pingReply.Status);
}
/// <summary>
/// Timestamp when the ping was sent.
/// </summary>
public DateTime Timestamp { get; set; }
/// <summary>
/// IP address of the host.
/// </summary>
public IPAddress IPAddress { get; set; }
/// <summary>
/// Hostname of the host.
/// </summary>
public string Hostname { get; set; }
/// <summary>
/// Bytes used to send the icmp packet.
/// </summary>
public int Bytes { get; set; }
/// <summary>
/// Time in milliseconds how long it took to receive a response.
/// </summary>
public long Time { get; set; }
/// <summary>
/// Time to live of the icmp packet.
/// </summary>
public int TTL { get; set; }
/// <summary>
/// IP status of the ping.
/// </summary>
public IPStatus Status { get; set; }
/// <summary>
/// IP address as an integer.
/// </summary>
public int IPAddressInt32 => IPAddress is { AddressFamily: AddressFamily.InterNetwork }
? IPv4Address.ToInt32(IPAddress)
: 0;
}