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


Python QTYPE.A属性代码示例

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


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

示例1: send_request

# 需要导入模块: from dnslib import QTYPE [as 别名]
# 或者: from dnslib.QTYPE import A [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:miketwes,项目名称:XX-Net-mini,代码行数:19,代码来源:dns_server.py

示例2: resolve

# 需要导入模块: from dnslib import QTYPE [as 别名]
# 或者: from dnslib.QTYPE import A [as 别名]
def resolve(self, request, handler):
        reply = request.reply()

        if request.q.qtype != QTYPE.A:
            log.error("Unsupported query qtype: `{}`".format(request.q.qtype))
            reply.header.rcode = getattr(RCODE, 'NXDOMAIN')
            return reply

        query = str(request.q.qname)
        if query not in self._records:
            log.error("qname `{}` not present in DB".format(query))
            reply.header.rcode = getattr(RCODE, 'NXDOMAIN')
            return reply

        log.info(
            "DNS query for `{}`, type `{}`, reply `{}`, ttl `{}`".format(
                query,
                request.q.qtype,
                self._records[query]['ip'],
                self._records[query]['ttl'])
        )

        reply.add_answer(
            *RR.fromZone("{} {} A {}".format(
                query,
                self._records[query]['ttl'],
                self._records[query]['ip'],
                )
            )
        )

        return reply 
开发者ID:dcos,项目名称:dcos,代码行数:34,代码来源:dns.py

示例3: on_udp_query

# 需要导入模块: from dnslib import QTYPE [as 别名]
# 或者: from dnslib.QTYPE import A [as 别名]
def on_udp_query(self, rsock, 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 = utils.to_bytes(str(request.questions[0].qname))

            if domain.endswith(b"."):
                domain = domain[:-1]

            type = request.questions[0].qtype
            if type not in [1, 28]:
                xlog.info("direct_query:%s type:%d", domain, type)
                return self.direct_query(rsock, request, addr)

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

            ips = self.query(domain, type)
            if not ips:
                xlog.debug("query:%s type:%d from:%s, get fail, cost:%d", domain, type, addr,
                           (time.time() - start_time) * 1000)

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

            rsock.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:miketwes,项目名称:XX-Net-mini,代码行数:43,代码来源:dns_server.py


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