当前位置: 首页>>代码示例>>Python>>正文


Python DNSRecord.add_answer方法代码示例

本文整理汇总了Python中dnslib.DNSRecord.add_answer方法的典型用法代码示例。如果您正苦于以下问题:Python DNSRecord.add_answer方法的具体用法?Python DNSRecord.add_answer怎么用?Python DNSRecord.add_answer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在dnslib.DNSRecord的用法示例。


在下文中一共展示了DNSRecord.add_answer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: on_udp_query

# 需要导入模块: from dnslib import DNSRecord [as 别名]
# 或者: from dnslib.DNSRecord import add_answer [as 别名]
    def on_udp_query(self, req_data, addr):
        start_time = time.time()
        try:
            request = DNSRecord.parse(req_data)
            if len(request.questions) != 1:
                xlog.warn("query num:%d %s", len(request.questions), request)
                return

            domain = str(request.questions[0].qname)

            type = request.questions[0].qtype
            if type not in [1, 28]:
                xlog.warn("query:%s type:%d", domain, type)

            # xlog.debug("DNS query:%s type:%d from %s", domain, type, addr)

            ips = self.query(domain, type)

            reply = DNSRecord(DNSHeader(id=request.header.id, qr=1, aa=1, ra=1, auth=1), q=request.q)
            for ip_cn in ips:
                ipcn_p = ip_cn.split("|")
                ip = ipcn_p[0]
                if "." in ip and type == 1:
                    reply.add_answer(RR(domain, ttl=60, rdata=A(ip)))
                elif ":" in ip and type == 28:
                    reply.add_answer(RR(domain, rtype=type, ttl=60, rdata=AAAA(ip)))
            res_data = reply.pack()

            self.serverSock.sendto(res_data, addr)
            xlog.debug("query:%s type:%d from:%s, return ip num:%d cost:%d", domain, type, addr,
                       len(reply.rr), (time.time()-start_time)*1000)
        except Exception as e:
            xlog.exception("on_query except:%r", e)
开发者ID:Libor87,项目名称:XX-Net,代码行数:35,代码来源:dns_server.py

示例2: manufactory_DNS

# 需要导入模块: from dnslib import DNSRecord [as 别名]
# 或者: from dnslib.DNSRecord import add_answer [as 别名]
 def manufactory_DNS(self):
     response_packet = DNSRecord()
     response_packet.header.id = self.query_id
     response_packet.add_question(DNSQuestion(self.qname, self.qtype))
     related_rr = filter(lambda rr: self.qname in rr, intercept_rr)
     for answer in related_rr:
         response_packet.add_answer(*RR.fromZone(answer))
     self.response_packet = response_packet.pack().__str__()
开发者ID:zhao-ji,项目名称:dns-intercept,代码行数:10,代码来源:dns_server.py

示例3: _reply

# 需要导入模块: from dnslib import DNSRecord [as 别名]
# 或者: from dnslib.DNSRecord import add_answer [as 别名]
 def _reply(self, rec, addrs=None):
     reply = DNSRecord(DNSHeader(id=rec.header.id, qr=1, aa=1, ra=1), q=rec.q)
     if addrs:
         if not isinstance(addrs, list):
             addrs = [addrs]
         for addr in addrs:
             reply.add_answer(RR(rec.q.qname, QTYPE.A, rdata=A(addr)))
     return reply.pack()
开发者ID:cnam,项目名称:docker-dns-rest,代码行数:10,代码来源:namesrv.py

示例4: _reply

# 需要导入模块: from dnslib import DNSRecord [as 别名]
# 或者: from dnslib.DNSRecord import add_answer [as 别名]
    def _reply(self, rec, addr=None):
        reply = DNSRecord(DNSHeader(id=rec.header.id, qr=1, aa=1, ra=1), q=rec.q)
        if addr:
            qtype = QTYPE.A if QTYPE.A == rec.q.qtype else QTYPE.AAAA
            reply.add_answer(RR(rec.q.qname, qtype, rdata=A(addr)))

        rep = reply.pack()
        return rep
开发者ID:jripault,项目名称:docker-dns,代码行数:10,代码来源:dockerdns.py

示例5: send_dns_packet

# 需要导入模块: from dnslib import DNSRecord [as 别名]
# 或者: from dnslib.DNSRecord import add_answer [as 别名]
def send_dns_packet(sock, server_addr, name, ip, id):
    """
    Construct and send dns packet
    """
    ans = DNSRecord(DNSHeader(id=id, qr=1))
    ans.add_question(DNSQuestion(name))
    ans.add_answer(RR(name, ttl=3600, rdata=A(ip)))
    # print(ans)
    sock.sendto(ans.pack(), (server_addr, 7131))
开发者ID:danmir,项目名称:Dns-Poison-Cache,代码行数:11,代码来源:perform_attack.py

示例6: handle_dns_packet

# 需要导入模块: from dnslib import DNSRecord [as 别名]
# 或者: from dnslib.DNSRecord import add_answer [as 别名]
 def handle_dns_packet(self, query: DNSRecord, answer: DNSRecord):
     if self.domain and query.q.qname.matchSuffix(self.domain):
         if query.q.qtype in (QTYPE.A, QTYPE.ANY):
             dnsname = query.q.qname.stripSuffix(self.domain)
             ipaddr  = self.get_hostname_ip(dnsname.label[-1])
             if ipaddr:
                 answer.add_answer(
                     RR(rname=query.q.qname, rtype=QTYPE.A, ttl=3600, rdata=RDMAP["A"](inet_ntoa(ipaddr)))
                 )
         return self
开发者ID:vognev,项目名称:dhns,代码行数:12,代码来源:middlewares.py

示例7: cache_hit

# 需要导入模块: from dnslib import DNSRecord [as 别名]
# 或者: from dnslib.DNSRecord import add_answer [as 别名]
 def cache_hit(self):
     cache_key = "cache:{}:{}".format(self.qtype, self.qname)
     cache_ret = cache_db.get(cache_key)
     if cache_ret:
         log.info("cache_hit: {}".format(self.query_id))
         response_packet = DNSRecord()
         response_packet.header.id = self.query_id
         response_packet.add_question(DNSQuestion(self.qname))
         for answer in loads(cache_ret):
             response_packet.add_answer(answer)
         log.info(response_packet.__str__())
         log.info("DNS response id {}".format(self.query_id))
         response_packet_str = response_packet.pack().__str__()
         self.wfile.write(response_packet_str)
         return True
开发者ID:zhao-ji,项目名称:gecko,代码行数:17,代码来源:dns_server.py

示例8: read_query_a

# 需要导入模块: from dnslib import DNSRecord [as 别名]
# 或者: from dnslib.DNSRecord import add_answer [as 别名]
	def read_query_a(self, request):		
		
		qname = request.q.qname
		
		id = request.header.id		
		if qname.label[0] in implant_id:
			

			if qname.label[1] == 'START':
				#print "Limplant envoie le debut des resultats"
				reponse = DNSRecord(DNSHeader(id=id, qr=1, aa=1, ra=1), q=request.q)				
				reponse.add_answer(RR(qname, QTYPE.TXT,   rdata=TXT(dodo)))		
				self.send_data(reponse)				
			
			if qname.label[1] == 'STARTFF':
				#print "Limplant envoie le debut des resultats"
				reponse = DNSRecord(DNSHeader(id=id, qr=1, aa=1, ra=1), q=request.q)				
				reponse.add_answer(RR(qname, QTYPE.TXT,   rdata=TXT(dodo)))		
				self.send_data(reponse)
							

			elif qname.label[1] == 'BODY':
				
				str1 = ''.join(qname.label[2:-3])
				#print "L'implant renvoie le resultat suivant: "
				print '\n'+str1.decode("hex")	
				reponse = DNSRecord(DNSHeader(id=id, qr=1, aa=1, ra=1), q=request.q)				
				reponse.add_answer(RR(qname, QTYPE.TXT,   rdata=TXT(dodo)))		
				self.send_data(reponse)
				
			elif qname.label[1] == 'FFBODY':
				
				str1 = ''.join(qname.label[3:-3])
				result.append(str1.decode("hex"))
				reponse = DNSRecord(DNSHeader(id=id, qr=1, aa=1, ra=1), q=request.q)				
				reponse.add_answer(RR(qname, QTYPE.TXT,   rdata=TXT(dodo)))		
				self.send_data(reponse)							

			elif qname.label[1] == 'END':
				#print "Limplant envoie la fin des resultats"		
				reponse = DNSRecord(DNSHeader(id=id, qr=1, aa=1, ra=1), q=request.q)				
				reponse.add_answer(RR(qname, QTYPE.TXT,   rdata=TXT(dodo)))		
				self.send_data(reponse)				
				str1 = ''.join(result)
				print '\n'+str1
				del result[:]
开发者ID:topotam,项目名称:LaMarre,代码行数:48,代码来源:serverdns.py

示例9: lookup_local

# 需要导入模块: from dnslib import DNSRecord [as 别名]
# 或者: from dnslib.DNSRecord import add_answer [as 别名]
def lookup_local(handler, request):
    qn2 = qn = request.q.qname
    qt = QTYPE[request.q.qtype]

    reply = DNSRecord(
        DNSHeader(id=request.header.id, qr=1, aa=1, ra=1),
        q=request.q
    )

    is_local = False
    for value in globalvars.local_domains.values():
        domain = value['domain']
        if globalvars.config['smartdns']['hack_srv'] and qt == 'SRV' and \
                not domain.inDomain(qn2):
            r_srv = b'.'.join(qn.label[:2])
            if r_srv.decode().lower() in globalvars.config['smartdns']['hack_srv']:
                qn2 = DNSLabel(domain.get_subdomain('@')).add(r_srv)
                logger.warn('\tChange SRV request to %s from %s' % (qn2, qn))

        if domain.inDomain(qn2):
            is_local = True
            rr_data = domain.search(qn2, qt)
            for r in rr_data:
                answer = RR(
                    rname=r['name'],
                    rtype=getattr(QTYPE, r['type']),
                    rclass=1, ttl=60 * 5,
                    rdata=r['rdata'],
                )
                reply.add_answer(answer)
            if reply.rr:
                break

    if is_local:
        if reply.rr:
            lines = []
            for r in reply.rr:
                rqn = str(r.rdata)
                rqt = QTYPE[r.rtype]
                lines.append('\t\t%s(%s)' % (rqn, rqt))
            logger.info('\tReturn from LOCAL:\n%s' % '\n'.join(lines))
            logger.debug('\n' + str(reply))
        else:
            logger.info('\tReturn from LOCAL: \n\t\tN/A')
        handler.send_data(reply.pack())
    return is_local
开发者ID:liuyug,项目名称:homedns,代码行数:48,代码来源:server.py

示例10: dns_handler

# 需要导入模块: from dnslib import DNSRecord [as 别名]
# 或者: from dnslib.DNSRecord import add_answer [as 别名]
def dns_handler(s, peer, data):
    request = DNSRecord.parse(data)
    id = request.header.id
    qname = request.q.qname
    qtype = request.q.qtype
    print "------ Request (%s): %r (%s)" % (str(peer), qname.label, QTYPE[qtype])

    reply = DNSRecord(DNSHeader(id=id, qr=1, aa=1, ra=1), q=request.q)
    if qtype == QTYPE.A:
        reply.add_answer(RR(qname, qtype, rdata=A(IP)))
    elif qtype == QTYPE["*"]:
        reply.add_answer(RR(qname, QTYPE.A, rdata=A(IP)))
        reply.add_answer(RR(qname, QTYPE.MX, rdata=MX(IP)))
        reply.add_answer(RR(qname, QTYPE.TXT, rdata=TXT(TXT)))
    else:
        reply.add_answer(RR(qname, QTYPE.CNAME, rdata=CNAME(TXT)))

    s.sendto(reply.pack(), peer)
开发者ID:ruletko,项目名称:pydnsd,代码行数:20,代码来源:gevent_server.py

示例11: query

# 需要导入模块: from dnslib import DNSRecord [as 别名]
# 或者: from dnslib.DNSRecord import add_answer [as 别名]
    def query(self, peer, request):
        id = request.header.id
        qname = request.q.qname

        print(
            "DNS Request for qname({0:s})".format(str(qname)),
            file=sys.stderr
        )

        reply = DNSRecord(
            DNSHeader(id=id, qr=1, aa=1, ra=1),
            q=request.q
        )

        # Add A Record
        reply.add_answer(RR(qname, QTYPE.A, rdata=A("127.0.0.1")))

        # Send To Client
        self.fire(write(peer, reply.pack()))
开发者ID:AdricEpic,项目名称:circuits,代码行数:21,代码来源:dnsserver.py

示例12: read

# 需要导入模块: from dnslib import DNSRecord [as 别名]
# 或者: from dnslib.DNSRecord import add_answer [as 别名]
    def read(self, sock, data):
        request = DNSRecord.parse(data)
        id = request.header.id
        qname = request.q.qname
        qtype = request.q.qtype
        print "------ Request (%s): %r (%s)" % (str(sock),
                qname.label, QTYPE[qtype])

        reply = DNSRecord(DNSHeader(id=id, qr=1, aa=1, ra=1), q=request.q)

        if qtype == QTYPE.A:
            reply.add_answer(RR(qname, qtype,      rdata=A(IP)))
        elif qtype == QTYPE['*']:
            reply.add_answer(RR(qname, QTYPE.A,    rdata=A(IP)))
            reply.add_answer(RR(qname, QTYPE.MX,   rdata=MX(IP)))
            reply.add_answer(RR(qname, QTYPE.TXT,  rdata=TXT(TXT)))
        else:
            reply.add_answer(RR(qname, QTYPE.CNAME, rdata=CNAME(TXT)))

        return reply.pack()
开发者ID:NinnOgTonic,项目名称:Out-of-Sight-Out-of-Mind-Rootkit,代码行数:22,代码来源:circuits_server.py

示例13: dns_handler

# 需要导入模块: from dnslib import DNSRecord [as 别名]
# 或者: from dnslib.DNSRecord import add_answer [as 别名]
def dns_handler(s, peer, data):
    # parse request
    request = DNSRecord.parse(data)
    name, _, domain = str(request.q.qname).partition(".")

    # create response
    reply = DNSRecord(DNSHeader(id=request.header.id, qr=1, aa=1, ra=1), q=request.q)

    # fill response
    if request.q.qtype == QTYPE.A or request.q.qtype == QTYPE['*']:
        ip = db_fetch(domain, name, "A")
        if ip:
            reply.add_answer(RR(request.q.qname, request.q.qtype, rdata=A(ip)))
    if request.q.qtype == QTYPE.AAAA or request.q.qtype == QTYPE['*']:
        ip = db_fetch(domain, name, "AAAA")
        if ip:
            ip = [ord(x) for x in socket.inet_pton(socket.AF_INET6, ip)]
            reply.add_answer(RR(request.q.qname, request.q.qtype, rdata=AAAA(ip)))

    # send response
    s.sendto(reply.pack(), peer)
开发者ID:shish,项目名称:tidydns,代码行数:23,代码来源:ddnsapp.py

示例14: read_query_txt

# 需要导入模块: from dnslib import DNSRecord [as 别名]
# 或者: from dnslib.DNSRecord import add_answer [as 别名]
	def read_query_txt(self, request):
		qname = request.q.qname
		id = request.header.id			
		if qname.label[0] == 'NEW':
				sys.stdout.flush()		
				print '\n[+] New implant! IMPLANT-ID %s' % str(id)
				str1 = ''.join(qname.label[1:-3])
				plop = str1.decode('hex')
				implant_info[str(id)] = plop.split('\n')	
			
				reponse = DNSRecord(DNSHeader(id=id, qr=1, aa=1, ra=1), q=request.q)				
				reponse.add_answer(RR(qname, QTYPE.TXT,   rdata=TXT(str(id))))		
				implant_id.append(str(id))				
				self.send_data(reponse)
				
		if qname.label[0] in implant_id:		
			if qname.label[1] == 'TOPO':
				now = datetime.datetime.now()
				localtime= now.strftime("%Y-%m-%d %H:%M")
				implant_info[qname.label[0]][4] = localtime

				if command.get(qname.label[0]):
					#print "[+] Implant %s poll, commandes pretes, au travail petit hippo!!" % str(qname.label[0])
					reponse = DNSRecord(DNSHeader(id=id, qr=1, aa=1, ra=1), q=request.q)				
					reponse.add_answer(RR(qname, QTYPE.TXT,   rdata=TXT(command.get(qname.label[0]))))
					self.send_data(reponse)
					del command[qname.label[0]]
				else:
					#print "[+] Implant %s poll , aucunes commandes, fait dodo petit hippo" % str(qname.label[0])
					reponse = DNSRecord(DNSHeader(id=id, qr=1, aa=1, ra=1), q=request.q)				
					reponse.add_answer(RR(qname, QTYPE.TXT,   rdata=TXT(dodo)))		
					self.send_data(reponse)
				pass
开发者ID:topotam,项目名称:LaMarre,代码行数:35,代码来源:serverdns.py

示例15: request

# 需要导入模块: from dnslib import DNSRecord [as 别名]
# 或者: from dnslib.DNSRecord import add_answer [as 别名]
    def request(self, s, peer, data):
        """
        Handle DNS Request

        @method  request
        @param   {socket}  s      Connection Socket
        @param   {peer}    peer   Peer Connecection
        @param   {mixed}   data   Data
        @return  {void}
        """

        # DNS Request Data
        request = DNSRecord.parse(data)
        id = request.header.id
        qname = request.q.qname
        qtype = request.q.qtype

        logging.info('DNS Request for qname(%s)' % qname)

        # Lookup IP Address
        ip = self.aliases.get(str(qname), False)

        # NOAUTH
        if ip is False:
            reply = DNSRecord(
                        DNSHeader(id=id, qr=1, aa=1, ra=1, rcode=9),
                        q=request.q)
        else:
            reply = DNSRecord(
                        DNSHeader(id=id, qr=1, aa=1, ra=1),
                        q=request.q)

            # Add A Record
            reply.add_answer(RR(qname, QTYPE.A, rdata=A(ip)))

        # Send To Client
        return self.s.sendto(reply.pack(), peer)
开发者ID:carriercomm,项目名称:dockerns,代码行数:39,代码来源:dnsserver.py


注:本文中的dnslib.DNSRecord.add_answer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。