Advertisement
cooperlees

Simple UDP Packet Generation

Sep 3rd, 2018
497
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.47 KB | None | 0 0
  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))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement