def _do_query(cls, buf, offset): qry = {} offset, name = cls._do_name(buf, offset) qry['Qname'] = name fmt = "!HH" reqlen = struct.calcsize(fmt) strng = buf[offset:offset + reqlen] res = struct.unpack(fmt, strng) qry['Qtype'] = type_to_text(res[0]) qry['Qclass'] = class_to_text(res[1]) return offset + reqlen, qry
def do_query(buf, offset): qry={} offset, name= do_name(buf, offset) qry['Qname']= name fmt= "!HH" reqlen= struct.calcsize(fmt) str= buf[offset:offset+reqlen] res= struct.unpack(fmt, str) qry['Qtype']= type_to_text(res[0]) qry['Qclass']= class_to_text(res[1]) offset= offset+reqlen return offset, qry
def _do_rr(cls, buf, offset): edns0_opt_nsid = 3 # this is also hardcoded in dns.edns.py error = [] rr = {} res = cls._do_name(buf, offset) if res is None: e = ("_do_rr", offset, "_do_name failed") error.append(e) return None offset, name = res rr['Name'] = name fmt = "!HHIH" reqlen = struct.calcsize(fmt) dat = buf[offset:offset + reqlen] res = struct.unpack(fmt, dat) rr['Type'] = type_to_text(res[0]) rr['Class'] = class_to_text(res[1]) rr['TTL'] = res[2] rr['RDlength'] = res[3] offset += reqlen rdata = buf[offset:offset + rr['RDlength']] rdata_offset = offset offset = offset + rr['RDlength'] if rr['Type'] == 'OPT': # this is per type_to_text function edns0 = { 'UDPsize': res[1], 'ExtendedReturnCode': res[2] >> 24, 'Version': (res[2] and 0x0f00) >> 16, 'Z': (res[2] and 0x00ff), 'Type': 'OPT', 'Option': [], 'Name': name, } o = 0 while o < len(rdata): fmt = "!HH" reqlen = struct.calcsize(fmt) dat = rdata[o:o + reqlen] res = struct.unpack(fmt, dat) opt = { 'OptionCode': res[0], 'OptionLength': res[1], } o += reqlen if opt['OptionCode'] == edns0_opt_nsid: opt['OptionName'] = 'NSID' opt[opt['OptionName']] = rdata[o:o + opt['OptionLength']] o = o + opt['OptionLength'] edns0['Option'].append(opt) del rr['Class'] del rr['RDlength'] del rr['TTL'] del rr['Name'] del rr['Type'] rr['EDNS0'] = edns0 return offset, rr if rr['Type'] == 'A' and rr[ 'Class'] == "IN": # this is per type_to_text function fmt = "!BBBB" a, b, c, d = struct.unpack(fmt, rdata) rr['Address'] = str(a) + '.' + str(b) + '.' + str(c) + '.' + str(d) if rr['Type'] == 'NS' and rr[ 'Class'] == "IN": # this is per type_to_text function doffset, name = cls._do_name(buf, rdata_offset) rr['Target'] = name return offset, rr
def do_rr(buf, offset): # TYPE_EDNS0 = 41 # This is also OPT in type_to_text function EDNS0_OPT_NSID = 3 # this is also hardcoded in dns.edns.py error = [] rr = {} res = do_name(buf, offset) if res == None: e = ("do_rr", offset, "do_name failed") error.append(e) return None offset, name = res rr['Name'] = name fmt = "!HHIH" reqlen = struct.calcsize(fmt) dat = buf[offset:offset + reqlen] res = struct.unpack(fmt, dat) rr['Type'] = type_to_text(res[0]) rr['Class'] = class_to_text(res[1]) rr['TTL'] = res[2] rr['RDlength'] = res[3] offset = offset + reqlen rdata = buf[offset:offset + rr['RDlength']] rdata_offset = offset offset = offset + rr['RDlength'] # if rr['Type'] == TYPE_EDNS0: # This is our internal method if rr['Type'] == 'OPT': # this is per type_to_text function edns0 = {} edns0['UDPsize'] = res[1] edns0['ExtendedReturnCode'] = res[2] >> 24 edns0['Version'] = (res[2] and 0x0f00) >> 16 edns0['Z'] = (res[2] and 0x00ff) edns0['Type'] = 'OPT' edns0['Option'] = {} edns0['Name'] = name # EDNS0 options o = 0 while o < len(rdata): fmt = "!HH" reqlen = struct.calcsize(fmt) dat = rdata[o:o + reqlen] res = struct.unpack(fmt, dat) opt = {} opt['OptionCode'] = res[0] opt['OptionLength'] = res[1] o = o + reqlen if opt['OptionCode'] == EDNS0_OPT_NSID: opt['OptionName'] = 'NSID' opt[opt['OptionName']] = rdata[o:o + opt['OptionLength']] o = o + opt['OptionLength'] edns0['Option'] = opt del rr['Class'] del rr['RDlength'] del rr['TTL'] del rr['Name'] del rr['Type'] rr['EDNS0'] = edns0 return offset, rr if rr['Type'] == 'A' and rr[ 'Class'] == "IN": # this is per type_to_text function fmt = "!BBBB" a, b, c, d = struct.unpack(fmt, rdata) rr['Address'] = str(a) + '.' + str(b) + '.' + str(c) + '.' + str(d) if rr['Type'] == 'NS' and rr[ 'Class'] == "IN": # this is per type_to_text function doffset, name = do_name(buf, rdata_offset) rr['Target'] = name #rdata[2:rr['RDlength']-2] return offset, rr
def _do_rr(cls, buf, offset): edns0_opt_nsid = 3 # this is also hardcoded in dns.edns.py error = [] rr = {} res = cls._do_name(buf, offset) if res is None: e = ("_do_rr", offset, "_do_name failed") error.append(e) return None offset, name = res rr['Name'] = name fmt = "!HHIH" reqlen = struct.calcsize(fmt) dat = buf[offset:offset + reqlen] res = struct.unpack(fmt, dat) rr['Type'] = type_to_text(res[0]) rr['Class'] = class_to_text(res[1]) rr['TTL'] = res[2] rr['RDlength'] = res[3] offset += reqlen rdata = buf[offset:offset + rr['RDlength']] rdata_offset = offset offset = offset + rr['RDlength'] if rr['Type'] == 'OPT': # this is per type_to_text function edns0 = { 'UDPsize': res[1], 'ExtendedReturnCode': res[2] >> 24, 'Version': (res[2] and 0x0f00) >> 16, 'Z': (res[2] and 0x00ff), 'Type': 'OPT', 'Option': [], 'Name': name, } o = 0 while o < len(rdata): fmt = "!HH" reqlen = struct.calcsize(fmt) dat = rdata[o:o + reqlen] res = struct.unpack(fmt, dat) opt = { 'OptionCode': res[0], 'OptionLength': res[1], } o += reqlen if opt['OptionCode'] == edns0_opt_nsid: opt['OptionName'] = 'NSID' opt[opt['OptionName']] = rdata[o:o + opt['OptionLength']] o = o + opt['OptionLength'] edns0['Option'].append(opt) del rr['Class'] del rr['RDlength'] del rr['TTL'] del rr['Name'] del rr['Type'] rr['EDNS0'] = edns0 return offset, rr if rr['Type'] == 'A' and rr['Class'] == "IN": # this is per type_to_text function fmt = "!BBBB" a, b, c, d = struct.unpack(fmt, rdata) rr['Address'] = str(a) + '.' + str(b) + '.' + str(c) + '.' + str(d) if rr['Type'] == 'NS' and rr['Class'] == "IN": # this is per type_to_text function doffset, name = cls._do_name(buf, rdata_offset) rr['Target'] = name return offset, rr
def do_rr(buf, offset): # TYPE_EDNS0 = 41 # This is also OPT in type_to_text function EDNS0_OPT_NSID = 3 # this is also hardcoded in dns.edns.py error = [] rr = {} res= do_name(buf, offset) if res == None: e= ("do_rr", offset, "do_name failed") error.append(e) return None offset, name= res rr['Name']= name fmt= "!HHIH" reqlen= struct.calcsize(fmt) dat= buf[offset:offset+reqlen] res= struct.unpack(fmt, dat) rr['Type']= type_to_text(res[0]) rr['Class']= class_to_text(res[1]) rr['TTL']= res[2] rr['RDlength']= res[3] offset= offset+reqlen rdata= buf[offset:offset+rr['RDlength']] rdata_offset= offset offset= offset+rr['RDlength'] # if rr['Type'] == TYPE_EDNS0: # This is our internal method if rr['Type'] == 'OPT': # this is per type_to_text function edns0= {} edns0['UDPsize']= res[1] edns0['ExtendedReturnCode']= res[2] >> 24 edns0['Version']= (res[2] and 0x0f00) >> 16 edns0['Z']= (res[2] and 0x00ff) edns0['Type']= 'OPT' edns0['Option']= {} edns0['Name']= name # EDNS0 options o= 0 while o < len(rdata): fmt= "!HH" reqlen= struct.calcsize(fmt) dat= rdata[o:o+reqlen] res= struct.unpack(fmt, dat) opt= {} opt['OptionCode']= res[0] opt['OptionLength']= res[1] o=o+reqlen if opt['OptionCode'] == EDNS0_OPT_NSID: opt['OptionName']= 'NSID' opt[opt['OptionName']]= rdata[o:o+opt['OptionLength']] o=o+opt['OptionLength'] edns0['Option'] = opt del rr['Class'] del rr['RDlength'] del rr['TTL'] del rr['Name'] del rr['Type'] rr['EDNS0'] = edns0 return offset, rr if rr['Type'] == 'A' and rr['Class'] == "IN": # this is per type_to_text function fmt= "!BBBB" a,b,c,d = struct.unpack(fmt, rdata) rr['Address'] = str(a)+'.'+str(b)+'.'+str(c)+'.'+str(d) if rr['Type'] == 'NS' and rr['Class'] == "IN": # this is per type_to_text function doffset,name = do_name(buf,rdata_offset) rr['Target'] = name #rdata[2:rr['RDlength']-2] return offset, rr