Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Simple NTP query
require 'socket'
s = UDPSocket.new
NTP_PACKET_SIZE= 48
EPOCH_SECONDS = 2208988800
ntppacket = [0b11100011, 0, 6, 0xEC, 0, 49, 0x4E, 49, 52,0,0,0,0].pack("C4QC4Q4")
puts "Packet size matches: #{ntppacket.bytes.count == NTP_PACKET_SIZE}"
s.send ntppacket, 0, "pool.ntp.org", 123
response = s.recv(NTP_PACKET_SIZE)
z, time = response.unpack("A40N")
puts "Time received: #{time} seconds since 1900"
epoch = time - EPOCH_SECONDS
p Time.at epoch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.