How to use the aquests.protocols.dns.pydns.Lib function in aquests

To help you get started, we’ve selected a few aquests examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hansroh / aquests / aquests / protocols / dns / asyndns.py View on Github external
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:
github hansroh / aquests / aquests / protocols / dns / clients.py View on Github external
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 ()
github hansroh / aquests / aquests / protocols / dns / __init__.py View on Github external
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 ()
github hansroh / aquests / aquests / protocols / dns / asyndns.py View on Github external
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 ()
github hansroh / aquests / aquests / protocols / dns / clients.py View on Github external
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)
github hansroh / aquests / aquests / protocols / dns / asyndns.py View on Github external
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:
github hansroh / aquests / aquests / protocols / dns / asyndns.py View on Github external
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)
github hansroh / aquests / aquests / protocols / dns / asyndns.py View on Github external
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']:
github hansroh / aquests / aquests / protocols / dns / asyndns.py View on Github external
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)
github hansroh / aquests / aquests / protocols / dns / __init__.py View on Github external
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)