Surprise! We've been running on hardware provided by BuyVM for a few months and wanted to show them a little appreciation.
Running a paste site comes with unique challenges, ones that aren't always obvious and hard to control. As such, BuyVM offered us a home where we could worry less about the hosting side of things and focus on maintaining a clean and useful service! Go check them out and show them some love!
Description: SNTP Client
Submitted on February 4, 2017 at 07:07 AM

Section 1 (Python)

#!/usr/bin/env python3

import sys
import time
import struct
from socket import socket, AF_INET, SOCK_DGRAM
from contextlib import closing

NTP_QUERY = b'\x1b' + 47 * b'\0'
NTP_DELTA = 86400 * (70 * 365 + 17)  # seconds from 1900 to 1970
NTP_PACKET_FORMAT = '!12I'


def ntp_time(host="pool.ntp.org", port=123):
    with closing(socket(AF_INET, SOCK_DGRAM)) as client:
        client.sendto(NTP_QUERY, (host, port))
        response, address = client.recvfrom(1024)
    if response:
        unpacked = struct.unpack(NTP_PACKET_FORMAT,
            response[0:struct.calcsize(NTP_PACKET_FORMAT)])
    return unpacked[10] + float(unpacked[11]) / 2 ** 32 - NTP_DELTA


if __name__ == '__main__':
    try:
        sys.argv[1]
    except IndexError:
        pass
    print(time.ctime(ntp_time()))