Here is a DNS message. Answer the following questions about it:
Hint, you will definitely want to google and find the RFC or some other detailed source that describes the format of the request/response in detail. You might also capture a DNS message in Wireshark, and use that as an example.
44 02 81 80
00 01 00 01
00 00 00 00
0c 72 61 6d
62 6c 69 6e
77 72 65 63
6b 03 63 6f
6d 00 00 01
00 01 c0 0c
00 01 00 01
00 00 06 2b
00 04 40 1e
e4 14
In [28]:
dec = int('0x10',16)
dec
Out[28]:
In [29]:
# logical and and or
print(bin(16),bin(1),bin(16|1))
print(bin(16),bin(1),bin(16&1))
# Note that bin removes the leading zeros.
In [30]:
# Converting to characters -- Also you can google a hex ascii table
chr(int('0x73',16))
Out[30]:
In [31]:
id = int('0x4402',16)
print('The ID is',id)
In [32]:
def toBinStr(num,spaces=False):
num = int(num,16)
num=bin(num)
length = len(num)
outStr = ((8-(length-2)) * '0') + num[2:]
if spaces:
outStr = outStr[:4] + ' ' + outStr[4:]
return outStr
flagsOne = toBinStr('0x81',True)
flagsTwo = toBinStr('0x80', True)
flagsOne + ' ' + flagsTwo
Out[32]:
In [33]:
totalStr = toBinStr('0x81') + toBinStr('0x80')
msgType = totalStr[1:5]
print("The type code is",int(msgType,2))
In [34]:
print("The length of the host name is",str(int('0x0c',16)),' characters long.')
print("The name of the requested host is 72 61 6d 62 6c 69 6e 77 72 65 63 6b in hex or 'ramblinwreck'")
print("The extension of the name is 3 bytes long and 63 6f 6d in hex or 'com'")
In [35]:
print(str(int('0x40',16)),str(int('0x1e',16)),str(int('0xe4',16)),str(int('0x14',16)))
In [36]:
ttl = int('0x062b',16)
print("The TTL is",ttl,'seconds, or',ttl/60,'minutes.')