Skip to content

Instantly share code, notes, and snippets.

@arsatiki
Created February 23, 2016 13:28
Show Gist options
  • Select an option

  • Save arsatiki/d0526fb41fa93a15d36f to your computer and use it in GitHub Desktop.

Select an option

Save arsatiki/d0526fb41fa93a15d36f to your computer and use it in GitHub Desktop.
import socket
from struct import Struct
VERSION = 3
CLIENT_MODE = 3
LI = 0
NTP = Struct("!4c 3I 4Q I 16s")
def create_packet():
LIVNMode = LI << 6 | VERSION << 3 | CLIENT_MODE
return NTP.pack(chr(LIVNMode), '\0', '\0', '\0',
0, 0, 0,
0, 0, 0, 0,
0,
'\0'*16)
TARGET = '86.60.160.70'
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.bind(('127.0.0.1', 5005))
sock.sendto(create_packet(), (TARGET, 123))
reply, _ = sock.recvfrom(NTP.size)
print NTP.unpack(reply)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment