Ejemplo n.º 1
0
        def lookup_remote_nameserver(que):
            s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
            if s.sendto(dns.pack(que), (self.nameserver, 53)) == 0:
                LOG.error('failed to query')
                raise Exception('query failed')

            _resp = s.recv(2048)
            LOG.debug("raw response: {}".format(repr(_resp)))
            resp = dns.unpack(_resp)
            return resp
Ejemplo n.º 2
0
        def lookup_remote_nameserver(que):
            s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
            if s.sendto(dns.pack(que), (self.nameserver, 53)) == 0:
                LOG.error('failed to query')
                raise Exception('query failed')

            _resp = s.recv(2048)
            LOG.debug("raw response: {}".format(repr(_resp)))
            resp = dns.unpack(_resp)
            return resp
Ejemplo n.º 3
0
    def on_query(self, sip, sport, req):
        def lookup_remote_nameserver(que):
            s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
            if s.sendto(dns.pack(que), (self.nameserver, 53)) == 0:
                LOG.error('failed to query')
                raise Exception('query failed')

            _resp = s.recv(2048)
            LOG.debug("raw response: {}".format(repr(_resp)))
            resp = dns.unpack(_resp)
            return resp

        # end lookup_remote_nameserver
        LOG.debug("raw query: {}".format(repr(req)))
        que = dns.unpack(req)
        LOG.debug("query: {}".format(que))
        host = self.engine.lookup(que.questions[0].qname)

        if not host:
            # reslov from remote nameserver.
            resp = lookup_remote_nameserver(que)
        else:
            qh = que.header
            qq = que.questions[0]
            resp = dns.DNSResponse(header=dns.DNSHeader(id=qh.id,
                                                        qr=1,
                                                        opcode=qh.opcode,
                                                        aa=qh.aa,
                                                        tc=qh.tc,
                                                        rd=qh.rd,
                                                        ra=qh.ra,
                                                        rcode=qh.rcode,
                                                        qdcount=1,
                                                        ancount=1,
                                                        nscount=0,
                                                        arcount=0),
                                   questions=que.questions,
                                   answers=[
                                       dns.DNSAnswer(name=qq.qname,
                                                     type=1,
                                                     class_=1,
                                                     ttl=255,
                                                     rdlength=4,
                                                     rdata=host)
                                   ])

        _resp = dns.pack(resp)
        LOG.debug("raw response: {}".format(repr(_resp)))
        LOG.debug("response: {}".format(resp))
        self.sock.sendto(_resp, (sip, sport))
Ejemplo n.º 4
0
    def on_query(self, sip, sport, req):
        def lookup_remote_nameserver(que):
            s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
            if s.sendto(dns.pack(que), (self.nameserver, 53)) == 0:
                LOG.error('failed to query')
                raise Exception('query failed')

            _resp = s.recv(2048)
            LOG.debug("raw response: {}".format(repr(_resp)))
            resp = dns.unpack(_resp)
            return resp
        # end lookup_remote_nameserver
        LOG.debug("raw query: {}".format(repr(req)))
        que = dns.unpack(req)
        LOG.debug("query: {}".format(que))
        host = self.engine.lookup(que.questions[0].qname)

        if not host:
            # reslov from remote nameserver.
            resp = lookup_remote_nameserver(que)
        else:
            qh = que.header
            qq = que.questions[0]
            resp = dns.DNSResponse(
                header=dns.DNSHeader(
                    id=qh.id, qr=1, opcode=qh.opcode,
                    aa=qh.aa, tc=qh.tc, rd=qh.rd, ra=qh.ra,
                    rcode=qh.rcode, qdcount=1, ancount=1, nscount=0, arcount=0),
                questions=que.questions,
                answers=[dns.DNSAnswer(
                    name=qq.qname, type=1, class_=1, ttl=255,
                    rdlength=4, rdata=host)])

        _resp = dns.pack(resp)
        LOG.debug("raw response: {}".format(repr(_resp)))
        LOG.debug("response: {}".format(resp))
        self.sock.sendto(_resp, (sip, sport))