Created
February 23, 2016 13:28
-
-
Save arsatiki/d0526fb41fa93a15d36f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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