NtpClient Class
An NTP client for querying NTP servers to retrieve accurate network time. Supports NTPv3 and NTPv4.
public sealed class NtpClientRemarks
Responses are validated as described on NtpClientOptions.ValidateResponse, but they are never authenticated cryptographically. An attacker who can inject packets on the path to the server can still control the reported time.
Constructors
| Name | Description |
|---|---|
| NtpClient(string) | Initializes a new instance of the NtpClient class using default options (NTPv4, port 123). |
| NtpClient(string, NtpClientOptions?) | Initializes a new instance of the NtpClient class. |
NtpClient overloads
NtpClient(string)
NtpClient.csNtpClient(string, NtpClientOptions?)
NtpClient.csInitializes a new instance of the NtpClient class.
public NtpClient(string server, NtpClientOptions? options)Parameters
serverstring- The NTP server hostname or IP address.
optionsNtpClientOptions?- Optional configuration options.
Methods
| Name | Description |
|---|---|
| QueryAsync(CancellationToken) | Queries the NTP server and returns the time response. |
QueryAsync(CancellationToken)
NtpClient.csQueries the NTP server and returns the time response.
net10.0
public Task<NtpResponse> QueryAsync(CancellationToken cancellationToken = default)net11.0
public Task<NtpResponse> QueryAsync(CancellationToken cancellationToken = default)Parameters
cancellationTokenCancellationToken- A cancellation token.
Returns
Task<NtpResponse> The NTP response containing timestamps and computed offset/delay.
Exceptions
TimeoutException- Every resolved address timed out.
AggregateException- Every resolved address failed, for differing reasons.