3 ms·
Here's a portable version for those of us who do not use Bash: a=$(printf '\xb%-47.s' \ |nc -uw1 ntp.metas.ch 123 \ |exec xxd -s40 -l4 -p) b=$(printf
by 101914 11y ago
Here's a portable version for those of us who do not use Bash:
a=$(printf '\xb%-47.s' \
|nc -uw1 ntp.metas.ch 123 \
|exec xxd -s40 -l4 -p)
b=$(printf %d\\n 0x"$a")
c=$((b-2208988800))
date -r$c
There is a way to do the xxd step using original netcat.
Included with nc was a short program called nc-data.
It converts from btoa and atob for shoveling data to nc.
Slower than xxd but still useful. It also shows octal, decimal and byte number.
Another exercise might be a one-liner for the TAICLOCK protocol: http://cr.yp.to/proto/taiclock.txt http://cr.yp.to/proto/taiclock.txt (Alternative to SNTP with smaller packets and support for leap seconds.)