Created
October 8, 2015 12:56
-
-
Save piepieninja/6c7273f0cd19b10e5768 to your computer and use it in GitHub Desktop.
Short Name Server look up. I'll be honest I was competing with a friend to see who could get the shortest one, so some parts of this do not work in all cases.
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
| #!/usr/bin/env python | |
| import socket, sys, random | |
| DNS_IP = sys.argv[1][1:] | |
| DNS_NAME = sys.argv[2] | |
| MSG = '\xDB\x42\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00' | |
| names = DNS_NAME.split('.') | |
| for s in names: | |
| MSG += chr(len(s)) + s | |
| MSG = '\x00\x00\x01\x00\x01' | |
| sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | |
| sock.connect((DNS_IP, 53)) | |
| sock.send(MSG) | |
| data = sock.recv(1024) | |
| data = data.encode('hex') | |
| mark = 0 | |
| for x in range(24, len(data) - 2): | |
| if (data[x] == '0' and data[x +1] == '0'): | |
| mark = x | |
| break | |
| answers = int(data[12]+data[13]+data[14]+data[15]) | |
| while (answers != 0): | |
| print "IP: " + str(int((data[len(data) - (8*answers + answers-1)] + data[len(data) - (7*answers + answers-1)]), 16)) + "." + str(int((data[len(data) - (6*answers + answers-1)] + data[len(data) - (5*answers + answers-1)]), 16)) + "." + str(int((data[len(data) - (4*answers + answers-1)] + data[len(data) - (3*answers + answers-1)]), 16)) + "." + str(int((data[len(data) - (2*answers + answers-1)] + data[len(data) - (1*answers + answers-1)]), 16)) | |
| answers = answers - 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment