Simple UDP Packet Generation
cooperlees Sep 3rd, 2018 (edited) 88 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- #!/usr/bin/env python3
- import socket
- import struct
- import time
- host = "us.cooperlees.com"
- port = 123
- read_buffer = 1024
- address = (host, port)
- data = b'\x1b' + 47 * b'\0'
- epoch = 2208988800
- client = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
- client.sendto(data, address)
- data, address = client.recvfrom(read_buffer)
- # Unpack the binary data and get the seconds out
- t = struct.unpack("!12I", data)
- t -= epoch
- print("NTP Time = %s" % time.ctime(t))
RAW Paste Data