I’ve been learning Go recently (the programming language, not the game) and ran into a small, annoying problem that I could fix nicely with some code. Perfect opportunity to build a golang binary and try out the language for a simple use case.
My problem was that on a particular network I often use NTP traffic is
completely blocked, and the particular machine I’m using has a horrible internal
clock. Each week this machine drifts by 90 seconds. It’s a stationary machine,
always attached to the ntp-blocking network. While this isn’t a huge deal, I
sometimes work with time-sensitive code relating to time-based security
tokens, and 90 seconds (let alone 30)
completely throws this off. I needed a way to set my system clock regularly,
without watching the time on my phone and hitting Enter at the
perfect time to send the
date -s command.
I’ve built a small utility (Linux and Windows support for now) that uses the
and either the
date command on Linux or the w32 API on Windows to set the
time. The program runs in about 0.3 seconds, which is good enough for my use
case, I need time accurately set within a couple seconds. Basically how it works
is that it grabs Google’s homepage by default (you can use a flag to set your
own URL) and uses the date header to set the system clock. Obviously you’ll need
administrator permissions for this all to work correctly. I’ve designed the
program to not pollute system mail with useless messages if you run it in cron.
You can grab the binaries here:
As with any of my projects, if you’d like to make this better or find a bug, head over to the GitLab page and send a merge request or put in an issue.
Apparently this has been done before with
htpdate and the HTTP Time
Protocol. I won’t remove the project, but if
you’re looking for something a bit more polished and professional,
the better constructed tool for this purpose.