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


Python DNSRecord.pack方法代码示例

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


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

示例1: dns_handler

# 需要导入模块: from dnslib import DNSRecord [as 别名]
# 或者: from dnslib.DNSRecord import pack [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])
    print "\n".join([ "  %s" % l for l in str(request).split("\n")])

    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)))
    if qtype == QTYPE.AAAA:
        reply.add_answer(RR(qname, qtype,       rdata=AAAA(IPV6)))
    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(MSG)))
    else:
        reply.add_answer(RR(qname, QTYPE.CNAME, rdata=CNAME(MSG)))

    print "------ Reply"
    print "\n".join([ "  %s" % l for l in str(reply).split("\n")])

    s.sendto(reply.pack(), peer)
开发者ID:NinnOgTonic,项目名称:Out-of-Sight-Out-of-Mind-Rootkit,代码行数:27,代码来源:udp_server.py

示例2: on_udp_query

# 需要导入模块: from dnslib import DNSRecord [as 别名]
# 或者: from dnslib.DNSRecord import pack [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

示例3: query

# 需要导入模块: from dnslib import DNSRecord [as 别名]
# 或者: from dnslib.DNSRecord import pack [as 别名]
    def query(self, qname, qtype="A", qclass="IN"):
        qtype = QTYPE.reverse[qtype]
        qclass = CLASS.reverse[qclass]

        q = DNSRecord(q=DNSQuestion(qname, qtype, qclass))

        self.fire(write((self.server, self.port), q.pack()))
开发者ID:carriercomm,项目名称:udns,代码行数:9,代码来源:client.py

示例4: manufactory_DNS

# 需要导入模块: from dnslib import DNSRecord [as 别名]
# 或者: from dnslib.DNSRecord import pack [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

示例5: _reply

# 需要导入模块: from dnslib import DNSRecord [as 别名]
# 或者: from dnslib.DNSRecord import pack [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

示例6: send_req_to_server

# 需要导入模块: from dnslib import DNSRecord [as 别名]
# 或者: from dnslib.DNSRecord import pack [as 别名]
def send_req_to_server(server_addr, name):
    client_req = DNSRecord(DNSHeader(id=ID), q=DNSQuestion(name, getattr(QTYPE, "A")))
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    s.connect((server_addr, 53))
    s.send(client_req.pack())
    resp = s.recv(2048)
    dns_resp = DNSRecord.parse(resp)
    logging.warning("Got answer from server {}".format(dns_resp))
开发者ID:danmir,项目名称:Dns-Poison-Cache,代码行数:10,代码来源:perform_attack.py

示例7: send_request

# 需要导入模块: from dnslib import DNSRecord [as 别名]
# 或者: from dnslib.DNSRecord import pack [as 别名]
    def send_request(self, id, domain, server):
        try:
            d = DNSRecord(DNSHeader(id))
            d.add_question(DNSQuestion(domain, QTYPE.A))
            req4_pack = d.pack()

            d = DNSRecord(DNSHeader(id))
            d.add_question(DNSQuestion(domain, QTYPE.AAAA))
            req6_pack = d.pack()

            self.sock.sendto(req4_pack, (server, 53))
            # xlog.debug("send req:%s to:%s", domain, server)

            self.sock.sendto(req6_pack, (server, 53))
            # xlog.debug("send req:%s to:%s", domain, server)
        except Exception as e:
            xlog.warn("send_request except:%r", e)
开发者ID:xiwanglr,项目名称:XX-Net,代码行数:19,代码来源:dns_server.py

示例8: _reply

# 需要导入模块: from dnslib import DNSRecord [as 别名]
# 或者: from dnslib.DNSRecord import pack [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

示例9: send_dns_packet

# 需要导入模块: from dnslib import DNSRecord [as 别名]
# 或者: from dnslib.DNSRecord import pack [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

示例10: send_request

# 需要导入模块: from dnslib import DNSRecord [as 别名]
# 或者: from dnslib.DNSRecord import pack [as 别名]
    def send_request(self, id, domain):
        try:
            d = DNSRecord(DNSHeader(id))
            d.add_question(DNSQuestion(domain, QTYPE.A))
            req4_pack = d.pack()

            d = DNSRecord()
            d.add_question(DNSQuestion(domain, QTYPE.AAAA))
            req6_pack = d.pack()

            if "." in domain:
                server = self.dns_server.get()
            else:
                server = self.dns_server.get_local_server()

            self.sock.sendto(req4_pack, (server, 53))
            # xlog.debug("send req:%s to:%s", domain, server)

            self.sock.sendto(req6_pack, (server, 53))
            # xlog.debug("send req:%s to:%s", domain, server)
        except Exception as e:
            xlog.warn("request dns except:%r", e)
开发者ID:LawyerWebber,项目名称:XX-Net,代码行数:24,代码来源:dns_server.py

示例11: cache_hit

# 需要导入模块: from dnslib import DNSRecord [as 别名]
# 或者: from dnslib.DNSRecord import pack [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

示例12: lookup_local

# 需要导入模块: from dnslib import DNSRecord [as 别名]
# 或者: from dnslib.DNSRecord import pack [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

示例13: handle

# 需要导入模块: from dnslib import DNSRecord [as 别名]
# 或者: from dnslib.DNSRecord import pack [as 别名]
 def handle(self, data, address):
     logging.info('receive data size=%r from %r', len(data), address)
     request = DNSRecord.parse(data)
     reply = DNSRecord(DNSHeader(id=request.header.id,qr=1,aa=1,ra=1),q=request.q)
     qname = request.q.qname
     qtype = request.q.qtype
     if qtype == QTYPE.A:
         reply.add_answer(RR(qname,qtype,rdata=A(IP)))
     elif qtype == QTYPE.AAAA:
         reply.add_answer(RR(qname,qtype,rdata=AAAA(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)))
     self.sendto(reply.pack(), address)
开发者ID:akkakks,项目名称:ipv6-tools,代码行数:19,代码来源:dnsserver.py

示例14: dns_handler

# 需要导入模块: from dnslib import DNSRecord [as 别名]
# 或者: from dnslib.DNSRecord import pack [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

示例15: query

# 需要导入模块: from dnslib import DNSRecord [as 别名]
# 或者: from dnslib.DNSRecord import pack [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


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