Ejemplo n.º 1
0
 def resolve(self,request,handler):
     if handler.protocol == 'udp':
         proxy_r = request.send(self.address,self.port)
     else:
         proxy_r = request.send(self.address,self.port,tcp=True)
     reply = DNSRecord.parse(proxy_r)
     return reply
Ejemplo n.º 2
0
 def resolve(self, request, handler):
     if handler.protocol == 'udp':
         proxy_r = request.send(self.address, self.port)
     else:
         proxy_r = request.send(self.address, self.port, tcp=True)
     reply = DNSRecord.parse(proxy_r)
     return reply
Ejemplo n.º 3
0
    def get_reply(self, data):
        host, port = self.server.resolver.address, self.server.resolver.port

        request = DNSRecord.parse(data)
        self.log_request(request)

        if self.protocol == 'tcp':
            data = struct.pack("!H", len(data)) + data
            response = send_tcp(data, host, port)
            response = response[2:]
        else:
            response = send_udp(data, host, port)

        reply = DNSRecord.parse(response)
        self.log_reply(reply)

        return response
Ejemplo n.º 4
0
    def get_reply(self,data):
        host,port = self.server.resolver.address,self.server.resolver.port

        request = DNSRecord.parse(data)
        self.log_request(request)

        if self.protocol == 'tcp':
            data = struct.pack("!H",len(data)) + data
            response = send_tcp(data,host,port)
            response = response[2:]
        else:
            response = send_udp(data,host,port)

        reply = DNSRecord.parse(response)
        self.log_reply(reply)

        return response
Ejemplo n.º 5
0
    def get_reply(self,data):
        request = DNSRecord.parse(data)
        self.server.logger.log_request(self,request)

        resolver = self.server.resolver
        reply = resolver.resolve(request,self)
        self.server.logger.log_reply(self,reply)

        if self.protocol == 'udp':
            rdata = reply.pack()
            if self.udplen and len(rdata) > self.udplen:
                truncated_reply = reply.truncate()
                rdata = truncated_reply.pack()
                self.server.logger.log_truncated(self,truncated_reply)
        else:
            rdata = reply.pack()

        return rdata
Ejemplo n.º 6
0
    def get_reply(self, data):
        request = DNSRecord.parse(data)
        self.server.logger.log_request(self, request)

        resolver = self.server.resolver
        reply = resolver.resolve(request, self)
        self.server.logger.log_reply(self, reply)

        if self.protocol == 'udp':
            rdata = reply.pack()
            if self.udplen and len(rdata) > self.udplen:
                truncated_reply = reply.truncate()
                rdata = truncated_reply.pack()
                self.server.logger.log_truncated(self, truncated_reply)
        else:
            rdata = reply.pack()

        return rdata
Ejemplo n.º 7
0
 def resolve(self,request,handler):
     reply = request.reply()
     qname = request.q.qname
     qtype = QTYPE[request.q.qtype]
     # Try to resolve locally unless on skip list
     if not any([qname.matchGlob(s) for s in self.skip]):
         for name,rtype,rr in self.zone:
             if qname.matchGlob(name) and (qtype in (rtype,'ANY','CNAME')):
                 a = copy.copy(rr)
                 a.rname = qname
                 reply.add_answer(a)
     # Check for NXDOMAIN
     if any([qname.matchGlob(s) for s in self.nxdomain]):
         reply.header.rcode = getattr(RCODE,'NXDOMAIN')
         return reply
     # Otherwise proxy
     if not reply.rr:
         if handler.protocol == 'udp':
             proxy_r = request.send(self.address,self.port)
         else:
             proxy_r = request.send(self.address,self.port,tcp=True)
         reply = DNSRecord.parse(proxy_r)
     return reply
Ejemplo n.º 8
0
 def resolve(self, request, handler):
     reply = request.reply()
     qname = request.q.qname
     qtype = QTYPE[request.q.qtype]
     # Try to resolve locally unless on skip list
     if not any([qname.matchGlob(s) for s in self.skip]):
         for name, rtype, rr in self.zone:
             if qname.matchGlob(name) and (qtype
                                           in (rtype, 'ANY', 'CNAME')):
                 a = copy.copy(rr)
                 a.rname = qname
                 reply.add_answer(a)
     # Check for NXDOMAIN
     if any([qname.matchGlob(s) for s in self.nxdomain]):
         reply.header.rcode = getattr(RCODE, 'NXDOMAIN')
         return reply
     # Otherwise proxy
     if not reply.rr:
         if handler.protocol == 'udp':
             proxy_r = request.send(self.address, self.port)
         else:
             proxy_r = request.send(self.address, self.port, tcp=True)
         reply = DNSRecord.parse(proxy_r)
     return reply