daily pastebin goal
46%
SHARE
TWEET

Simple UDP Packet Generation

cooperlees Sep 3rd, 2018 (edited) 85 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python3
  2.  
  3. import socket
  4. import struct
  5. import time
  6.  
  7. host = "us.cooperlees.com"
  8. port = 123
  9. read_buffer = 1024
  10. address = (host, port)
  11. data = b'\x1b' + 47 * b'\0'
  12. epoch = 2208988800
  13.  
  14. client = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
  15. client.sendto(data, address)
  16.  
  17. data, address = client.recvfrom(read_buffer)
  18. # Unpack the binary data and get the seconds out
  19. t = struct.unpack("!12I", data)[10]
  20. t -= epoch
  21.  
  22. print("NTP Time = %s" % time.ctime(t))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top