Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

htpdate-go

A Go port of iridium77/htpdate: sync the system clock from HTTP Date: headers when NTP is blocked.

  • Concurrent multi-server polling with median offset
  • One-way latency correction (RTT/2) for sub-second accuracy in practice
  • Query-only by default — no privileges required
  • Optional clock adjustment with -s (root / Administrator)
  • Daemon mode (-i 10m) and JSON output (-j) for scripting
  • Pure stdlib + golang.org/x/sys; works on Linux, macOS, Windows

Install

go install github.com/pklotz/htpdate-go/cmd/htpdate@latest

…or build from source:

git clone https://github.com/pklotz/htpdate-go
cd htpdate-go
make build              # ./htpdate
make install PREFIX=/usr/local

Usage

# Just print the offset against one or more servers (no privileges).
htpdate https://www.google.com https://www.cloudflare.com

# Actually set the clock (Linux/macOS):
sudo htpdate -s https://www.google.com https://www.cloudflare.com

# Daemon: re-sync every 10 minutes.
sudo htpdate -i 10m -s https://www.google.com

# JSON output for scripts.
htpdate -j https://www.google.com | jq

Flags

Flag Default Description
-t 5s Per-request timeout
-i 0 Daemon interval; 0 = run once
-m HEAD HTTP method (HEAD or GET)
-u auto User-Agent header
-s false Apply the offset to the system clock
-j false JSON output
-k false Skip TLS verification
-v false Debug logging
-max-adjust 24h Refuse to set clock if offset exceeds this
-version Print version and exit

Accuracy

The HTTP Date: header has one-second resolution, so a single sample can be off by ±1s. htpdate-go corrects for round-trip time (offset = serverDate - (sendTime + RTT/2)) and takes the median across servers, which in practice gets you within ~100–500ms — good enough for log correlation, certificate validity, and Kerberos, but not a substitute for NTP/PTP when you need millisecond accuracy.

Development

make help        # show all targets
make test        # go test -race
make lint        # vet + staticcheck (if installed)
make release     # cross-compile to dist/

CI runs build + test on Linux, macOS, and Windows; see .github/workflows/ci.yml.

License

GPL-3.0 — see LICENSE.

About

HTTP Time Protocol (HTP) client written in Go

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages