Skip to main content
net10.0net11.0net8.0net9.0

An NTP client for querying NTP servers to retrieve accurate network time (supports NTPv3 and NTPv4)

Published
Jun 13, 2026
4mo ago
Total Downloads
835
835

Install

dotnet add package Meziantou.Framework.NtpClient --version 1.0.3
ProductVersions
.NET
net10.0net11.0net8.0net9.0

README

Meziantou.Framework.NtpClient

An NTP client library for querying NTP servers to retrieve accurate network time. Supports NTPv3 and NTPv4.

Features

  • NTPv3 and NTPv4: Configurable protocol version
  • Clock offset calculation: Computes the time difference between client and server
  • Round-trip delay: Measures network round-trip time
  • Async/await: Fully asynchronous API with cancellation support
  • OpenTelemetry: Built-in ActivitySource tracing for NTP queries

Usage

using Meziantou.Framework.Ntp;

// Query an NTP server using NTPv4 (default)
using var client = new NtpClient("pool.ntp.org");
var response = await client.QueryAsync();

Console.WriteLine($"Server time: {response.TransmitTimestamp}");
Console.WriteLine($"Clock offset: {response.ClockOffset}");
Console.WriteLine($"Round-trip delay: {response.RoundTripDelay}");
Console.WriteLine($"Stratum: {response.Stratum}");

Using NTPv3

using var client = new NtpClient("pool.ntp.org", new NtpClientOptions
{
    Version = NtpVersion.V3,
});
var response = await client.QueryAsync();

Cancellation and timeout

using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(10));
using var client = new NtpClient("time.google.com");
var response = await client.QueryAsync(cts.Token);

Custom port

using var client = new NtpClient("localhost", new NtpClientOptions
{
    Port = 12345,
});
var response = await client.QueryAsync();

Changes from Previous Version

v1.0.2v1.0.3
Added Frameworks
net11.0

Adoption Assessment

A verified publisher signal is available. Assess fit from the package's supported frameworks, license and dependency graph rather than popularity alone.

Compatibility metadata lists 4 target frameworks; confirm the exact target used by your application.

Related Guides & Workflows

Learn how to evaluate, integrate, or audit this package in your .NET project.