Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
err = 'EOF-invalid-header' % qname
count = Lib.unpack16bit(header)
reply = data [2: 2 + count]
if len (reply) != count:
err = "incomplete-reply"
else:
reply = data
except:
self.logger.trace ()
err = 'exception'
if not err:
try:
u = Lib.Munpacker(reply)
r = Lib.DnsResult(u, args)
r.args = args
if r.header ['tc']:
err = 'truncate'
args ['protocol'] = 'tcp'
self.logger ('%s, trucated switch to TCP' % qname, 'warn')
else:
if r.header ['status'] != 'NOERROR':
self.logger ('%s, status %s' % (qname, r.header ['status']), 'warn')
answers = r.answers
except:
self.logger.trace ()
if err:
if len (args ['errors']) < 2:
def query (self, request, args, callback):
self.event_time = time.time ()
self.reply = b""
self.header = None
self.request = request
self.args = args
self.callback = callback
args ['addr'] = self.addr
self.push (Lib.pack16bit(len(request)) + request)
if not self.connected:
self.set_terminator (2)
self.create_socket (socket.AF_INET, socket.SOCK_STREAM)
self._connect ()
err = 'EOF-invalid-header' % qname
count = Lib.unpack16bit(header)
reply = data [2: 2 + count]
if len (reply) != count:
err = "incomplete-reply"
else:
reply = data
except:
self.logger.trace ()
err = 'exception'
if not err:
try:
u = Lib.Munpacker(reply)
r = Lib.DnsResult(u, args)
r.args = args
if r.header ['tc']:
err = 'truncate'
args ['protocol'] = 'tcp'
self.logger ('%s, trucated switch to TCP' % qname, 'warn')
else:
if r.header ['status'] != 'NOERROR':
self.logger ('%s, status %s' % (qname, r.header ['status']), 'warn')
answers = [{"name": qname, "data": None, "status": r.header ['status']}]
else:
answers = r.answers
except:
self.logger.trace ()
def query (self, request, args, callback):
self.event_time = time.time ()
self.reply = b""
self.header = None
self.request = request
self.args = args
self.callback = callback
args ['addr'] = self.addr
self.push (Lib.pack16bit(len(request)) + request)
if not self.connected:
self.set_terminator (2)
self.create_socket (socket.AF_INET, socket.SOCK_STREAM)
self._connect ()
def found_terminator (self):
if self.header:
self.callback (self.args, self.header + self.reply, self._timeouted)
self.close ()
else:
self.header, self.reply = self.reply, b""
count = Lib.unpack16bit(self.header)
self.set_terminator (count)
if len (header) < 2:
err = 'EOF-invalid-header' % qname
count = Lib.unpack16bit(header)
reply = data [2: 2 + count]
if len (reply) != count:
err = "incomplete-reply"
else:
reply = data
except:
self.logger.trace ()
err = 'exception'
if not err:
try:
u = Lib.Munpacker(reply)
r = Lib.DnsResult(u, args)
r.args = args
if r.header ['tc']:
err = 'truncate'
args ['protocol'] = 'tcp'
self.logger ('%s, trucated switch to TCP' % qname, 'warn')
else:
if r.header ['status'] != 'NOERROR':
self.logger ('%s, status %s' % (qname, r.header ['status']), 'warn')
answers = r.answers
except:
self.logger.trace ()
if err:
def found_terminator (self):
if self.header:
self.callback (self.args, self.header + self.reply, self._timeouted)
self.close ()
else:
self.header, self.reply = self.reply, b""
count = Lib.unpack16bit(self.header)
self.set_terminator (count)
err = None
answers = []
qname = args ['name'].decode ('utf8')
if timeouted:
err = 'timeout'
else:
try:
if not data:
err = "no-reply"
else:
if args ["protocol"] == "tcp":
header = data [:2]
if len (header) < 2:
err = 'EOF-invalid-header' % qname
count = Lib.unpack16bit(header)
reply = data [2: 2 + count]
if len (reply) != count:
err = "incomplete-reply"
else:
reply = data
except:
self.logger.trace ()
err = 'exception'
if not err:
try:
u = Lib.Munpacker(reply)
r = Lib.DnsResult(u, args)
r.args = args
if r.header ['tc']:
protocol = args ['protocol']
opcode = args ['opcode']
rd = args ['rd']
if type(args['qtype']) in (bytes, str):
try:
qtype = getattr (Type, args ['qtype'].upper ())
except AttributeError:
raise Base.DNSError('%s unknown query type' % name)
else:
qtype = args ['qtype']
qname = args ['name']
m = Lib.Mpacker()
m.addHeader(self.get_id (),
0, opcode, 0, 0, rd, 0, 0, 0,
1, 0, 0, 0)
m.addQuestion (qname, qtype, Class.IN)
request = m.getbuf ()
conn = getattr (pool, args ['protocol']) (args.get ('addr'))
conn.query (request, args, self.process_reply)
protocol = args ['protocol']
opcode = args ['opcode']
rd = args ['rd']
if type(args['qtype']) in (bytes, str):
try:
qtype = getattr (Type, args ['qtype'].upper ())
except AttributeError:
raise Base.DNSError('%s unknown query type' % name)
else:
qtype = args ['qtype']
qname = args ['name']
m = Lib.Mpacker()
m.addHeader(self.get_id (),
0, opcode, 0, 0, rd, 0, 0, 0,
1, 0, 0, 0)
m.addQuestion (qname, qtype, Class.IN)
request = m.getbuf ()
conn = self.client_getter (args.get ('addr'), args ['protocol'])
conn.query (request, args, self.process_reply)