Exemplo n.º 1
0
def get_time():
    NTP_SERVER = '130.225.96.8'

    client = socket(AF_INET, SOCK_DGRAM)
    data = '\x1b' + 47 * '\0'
    client.settimeout(1)

    for i in xrange(20):
        try:
            start = clock.now()
            client.sendto(data, (NTP_SERVER, 123))
            data, address = client.recvfrom(1024)
            time_used = clock.now() - start
            break
        except timeout:
            time.sleep(.1 * i)
            continue

    if data:
        s = struct.unpack('!12I', data)
        return start, time_used, Dec(s[10]), Dec(s[11])
Exemplo n.º 2
0
#!/usr/bin/env python
from lib import clock
print int(clock.now() + 60)