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


Python dnslib.QTYPE属性代码示例

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


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

示例1: log_reply

# 需要导入模块: import dnslib [as 别名]
# 或者: from dnslib import QTYPE [as 别名]
def log_reply(self,handler,reply):
        if reply.header.rcode == RCODE.NOERROR:
            print("%sReply: [%s:%d] (%s) / '%s' (%s) / RRs: %s" % (
                    self.log_prefix(handler),
                    handler.client_address[0],
                    handler.client_address[1],
                    handler.protocol,
                    reply.q.qname,
                    QTYPE[reply.q.qtype],
                    ",".join([QTYPE[a.rtype] for a in reply.rr])))
        else:
            print("%sReply: [%s:%d] (%s) / '%s' (%s) / %s" % (
                    self.log_prefix(handler),
                    handler.client_address[0],
                    handler.client_address[1],
                    handler.protocol,
                    reply.q.qname,
                    QTYPE[reply.q.qtype],
                    RCODE[reply.header.rcode]))
        self.log_data(reply) 
开发者ID:paulc,项目名称:dnslib,代码行数:22,代码来源:server.py

示例2: query

# 需要导入模块: import dnslib [as 别名]
# 或者: from dnslib import QTYPE [as 别名]
def query(self, hostname, query_type='ANY', name_server=False, use_tcp=False):
        ret = []
        response = None
        if name_server == False:
            name_server = self.get_ns()
        else:
            self.wildcards = {}
            self.failed_code = None
        self.last_resolver = name_server
        query = dnslib.DNSRecord.question(hostname, query_type.upper().strip())
        try:
            response_q = query.send(name_server, 53, use_tcp, timeout=30)
            if response_q:
                response = dnslib.DNSRecord.parse(response_q)
            else:
                raise IOError("Empty Response")
        except Exception as e:
            # IOErrors are all conditions that require a retry.
            raise IOError(str(e))
        if response:
            self.rcode = dnslib.RCODE[response.header.rcode]
            for r in response.rr:
                try:
                    rtype = str(dnslib.QTYPE[r.rtype])
                except:  # Server sent an unknown type:
                    rtype = str(r.rtype)
                # Fully qualified domains may cause problems for other tools that use subbrute's output.
                rhost = str(r.rname).rstrip(".")
                ret.append((rhost, rtype, str(r.rdata)))
            # What kind of response did we get?
            if self.rcode not in ['NOERROR', 'NXDOMAIN', 'SERVFAIL', 'REFUSED']:
                trace('!Odd error code:', self.rcode, hostname, query_type)
            # Is this a perm error?  We will have to retry to find out.
            if self.rcode in ['SERVFAIL', 'REFUSED', 'FORMERR', 'NOTIMP', 'NOTAUTH']:
                raise IOError('DNS Failure: ' + hostname + " - " + self.rcode)
            # Did we get an empty body and a non-error code?
            elif not len(ret) and self.rcode != "NXDOMAIN":
                raise IOError("DNS Error - " + self.rcode + " - for:" + hostname)
        return ret 
开发者ID:superhedgy,项目名称:AttackSurfaceMapper,代码行数:41,代码来源:subbrute.py

示例3: query

# 需要导入模块: import dnslib [as 别名]
# 或者: from dnslib import QTYPE [as 别名]
def query(self, hostname, query_type = 'ANY', name_server = False, use_tcp = True):
        ret = []
        response = None
        if name_server == False:
            name_server = self.get_ns()
        else:
            self.wildcards = {}
            self.failed_code = None
        self.last_resolver = name_server
        query = dnslib.DNSRecord.question(hostname, query_type.upper().strip())
        try:
            response_q = query.send(name_server, 53, use_tcp)
            if response_q:
                response = dnslib.DNSRecord.parse(response_q)
            else:
                raise IOError("Empty Response")
        except Exception as e:
            #IOErrors are all conditions that require a retry.
            raise IOError(str(e))
        if response:
            self.rcode = dnslib.RCODE[response.header.rcode]
            for r in response.rr:
                try:
                    rtype = str(dnslib.QTYPE[r.rtype])
                except:#Server sent an unknown type:
                    rtype = str(r.rtype)
                #Fully qualified domains may cause problems for other tools that use subbrute's output.
                rhost = str(r.rname).rstrip(".")
                ret.append((rhost, rtype, str(r.rdata)))
            #What kind of response did we get?
            if self.rcode not in ['NOERROR', 'NXDOMAIN', 'SERVFAIL', 'REFUSED']:
                trace('!Odd error code:', self.rcode, hostname, query_type)
            #Is this a perm error?  We will have to retry to find out.
            if self.rcode in ['SERVFAIL', 'REFUSED', 'FORMERR', 'NOTIMP', 'NOTAUTH']:
                raise IOError('DNS Failure: ' + hostname + " - " + self.rcode)
            #Did we get an empty body and a non-error code?
            elif not len(ret) and self.rcode != "NXDOMAIN":
                raise IOError("DNS Error - " + self.rcode + " - for:" + hostname)
        return ret 
开发者ID:VainlyStrain,项目名称:Vaile,代码行数:41,代码来源:Resolver.py

示例4: handle

# 需要导入模块: import dnslib [as 别名]
# 或者: from dnslib import QTYPE [as 别名]
def handle(self):
        request = dnslib.DNSRecord.parse(self.packet).reply()
        qname = str(request.q.qname)
        record, ttl, recordType = self.server.getRecord(qname)
        answer = dnslib.DNSRecord.question(qname)
        request.add_answer(
            dnslib.RR(
                qname,
                getattr(dnslib.QTYPE, recordType),
                rdata=getattr(dnslib, recordType)(record),
                ttl=ttl
            )
        )
        print('[%s] %s %s %s' % (time.time(), self.client_address, qname, record))
        self.wfile.write(request.pack()) 
开发者ID:LyleMi,项目名称:Saker,代码行数:17,代码来源:dnsrebinding.py

示例5: __init__

# 需要导入模块: import dnslib [as 别名]
# 或者: from dnslib import QTYPE [as 别名]
def __init__(self, zone, glob=False):
        self.zone = [(rr.rname, QTYPE[rr.rtype], rr) for rr in RR.fromZone(zone)]
        self.glob = glob
        self.eq = 'matchGlob' if glob else '__eq__' 
开发者ID:shad0w008,项目名称:Scanver,代码行数:6,代码来源:dnslog.py

示例6: resolve

# 需要导入模块: import dnslib [as 别名]
# 或者: from dnslib import QTYPE [as 别名]
def resolve(self, request, handler):
        """
            Respond to DNS request - parameters are request packet & handler.
            Method is expected to return DNS response
        """
        reply = request.reply()
        qname = request.q.qname
        qtype = QTYPE[request.q.qtype]
        for name, rtype, rr in self.zone:
            # Check if label & type match
            if getattr(qname, self.eq)(name) and (
                    qtype == rtype or qtype == 'ANY' or rtype == 'CNAME'):
                # If we have a glob match fix reply label
                if self.glob:
                    a = copy.copy(rr)
                    a.rname = qname
                    reply.add_answer(a)
                else:
                    reply.add_answer(rr)
                # Check for A/AAAA records associated with reply and
                # add in additional section
                if rtype in ['CNAME', 'NS', 'MX', 'PTR']:
                    for a_name, a_rtype, a_rr in self.zone:
                        if a_name == rr.rdata.label and a_rtype in ['A', 'AAAA']:
                            reply.add_ar(a_rr)
        if not reply.rr:
            reply.header.rcode = RCODE.NXDOMAIN
        return reply 
开发者ID:shad0w008,项目名称:Scanver,代码行数:30,代码来源:dnslog.py

示例7: log_request

# 需要导入模块: import dnslib [as 别名]
# 或者: from dnslib import QTYPE [as 别名]
def log_request(self,handler,request):
        print("%sRequest: [%s:%d] (%s) / '%s' (%s)" % (
                    self.log_prefix(handler),
                    handler.client_address[0],
                    handler.client_address[1],
                    handler.protocol,
                    request.q.qname,
                    QTYPE[request.q.qtype]))
        self.log_data(request) 
开发者ID:paulc,项目名称:dnslib,代码行数:11,代码来源:server.py

示例8: log_truncated

# 需要导入模块: import dnslib [as 别名]
# 或者: from dnslib import QTYPE [as 别名]
def log_truncated(self,handler,reply):
        print("%sTruncated Reply: [%s:%d] (%s) / '%s' (%s) / RRs: %s" % (
                    self.log_prefix(handler),
                    handler.client_address[0],
                    handler.client_address[1],
                    handler.protocol,
                    reply.q.qname,
                    QTYPE[reply.q.qtype],
                    ",".join([QTYPE[a.rtype] for a in reply.rr])))
        self.log_data(reply) 
开发者ID:paulc,项目名称:dnslib,代码行数:12,代码来源:server.py

示例9: __init__

# 需要导入模块: import dnslib [as 别名]
# 或者: from dnslib import QTYPE [as 别名]
def __init__(self,zone,glob=False):
        """
            Initialise resolver from zone file.
            Stores RRs as a list of (label,type,rr) tuples
            If 'glob' is True use glob match against zone file
        """
        self.zone = [(rr.rname,QTYPE[rr.rtype],rr) for rr in RR.fromZone(zone)]
        self.glob = glob
        self.eq = 'matchGlob' if glob else '__eq__' 
开发者ID:paulc,项目名称:dnslib,代码行数:11,代码来源:zoneresolver.py

示例10: resolve

# 需要导入模块: import dnslib [as 别名]
# 或者: from dnslib import QTYPE [as 别名]
def resolve(self,request,handler):
        """
            Respond to DNS request - parameters are request packet & handler.
            Method is expected to return DNS response
        """
        reply = request.reply()
        qname = request.q.qname
        qtype = QTYPE[request.q.qtype]
        for name,rtype,rr in self.zone:
            # Check if label & type match
            if getattr(qname,self.eq)(name) and (qtype == rtype or
                                                 qtype == 'ANY' or
                                                 rtype == 'CNAME'):
                # If we have a glob match fix reply label
                if self.glob:
                    a = copy.copy(rr)
                    a.rname = qname
                    reply.add_answer(a)
                else:
                    reply.add_answer(rr)
                # Check for A/AAAA records associated with reply and
                # add in additional section
                if rtype in ['CNAME','NS','MX','PTR']:
                    for a_name,a_rtype,a_rr in self.zone:
                        if a_name == rr.rdata.label and a_rtype in ['A','AAAA']:
                            reply.add_ar(a_rr)
        if not reply.rr:
            reply.header.rcode = RCODE.NXDOMAIN
        return reply 
开发者ID:paulc,项目名称:dnslib,代码行数:31,代码来源:zoneresolver.py

示例11: resolve

# 需要导入模块: import dnslib [as 别名]
# 或者: from dnslib import QTYPE [as 别名]
def resolve(self,request,handler):
        matched = False
        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):
                    if qtype in (rtype,'ANY','CNAME'):
                        a = copy.copy(rr)
                        a.rname = qname
                        reply.add_answer(a)
                    matched = True
        # Check for NXDOMAIN
        if any([qname.matchGlob(s) for s in self.nxdomain]):
            reply.header.rcode = getattr(RCODE,'NXDOMAIN')
            return reply
        if matched and self.all_qtypes:
            return reply
        # Otherwise proxy, first checking forwards, then to upstream.
        upstream, upstream_port = self.address,self.port
        if not any([qname.matchGlob(s) for s in self.skip]):
            for name, ip, port in self.forward:
                if qname.matchGlob(name):
                    upstream, upstream_port = ip, port
        if not reply.rr:
            try:
                if handler.protocol == 'udp':
                    proxy_r = request.send(upstream,upstream_port,
                                    timeout=self.timeout)
                else:
                    proxy_r = request.send(upstream,upstream_port,
                                    tcp=True,timeout=self.timeout)
                reply = DNSRecord.parse(proxy_r)
            except socket.timeout:
                reply.header.rcode = getattr(RCODE,'SERVFAIL')

        return reply 
开发者ID:paulc,项目名称:dnslib,代码行数:41,代码来源:intercept.py

示例12: multiaddr

# 需要导入模块: import dnslib [as 别名]
# 或者: from dnslib import QTYPE [as 别名]
def multiaddr(self):
        items = []
        for rr in self.record.rr:
            addr = Address(
                domain=self.domain.strip("."),
                ip=str(rr.rdata).strip("."),
                rtype=dnslib.QTYPE[rr.rtype],
                rclass=dnslib.CLASS[rr.rclass],
                ttl=rr.ttl,
                counter=time.time() + rr.ttl,
                dns_name=self.bdns.name
            )
            items.append(addr)
        return MultiAddress(items) 
开发者ID:alexsilva,项目名称:MINI-DNS-Server,代码行数:16,代码来源:lookup.py

示例13: resolve

# 需要导入模块: import dnslib [as 别名]
# 或者: from dnslib import QTYPE [as 别名]
def resolve(self, request, handler):
        hostname = str(request.q.qname)
        ltype = request.q.qtype
        headers = {"Host": "dns.google.com"}

        try:
            if CACHE[hostname]['dt'] > datetime.datetime.now() - datetime.timedelta(minutes=30):
                print("Cache Hit: %s" % hostname)
                answer = CACHE[hostname][ltype]
            else:
                print("Cache Expired: %s" % hostname)
                del CACHE[hostname]
                raise Exception("Cache Expired")
        except:
            lookup_resp = requests.get('%sname=%s&type=%s' % (GOOGLE_DNS_URL,
                                                          hostname,
                                                          ltype),
                                   headers=headers,
                                   verify=False)

            if PINNED_CERT != lookup_resp.peercert:
                print(lookup_resp.peercert)
                if EXIT_ON_MITM:
                    print ("ERROR: REMOTE SSL CERT DID NOT MATCH EXPECTED (PINNED) "
                           "SSL CERT, EXITING IN CASE OF MAN IN THE MIDDLE ATTACK")
                    my_pid = os.getpid()
                    os.kill(my_pid, signal.SIGINT)
                else:
                    print ("WARNING: REMOTE SSL CERT DID NOT MATCH EXPECTED (PINNED) "
                           "SSL CERT. NOT EXITING, BECAUSE YOU SAID SO IN YOUR CONFIG")


            if lookup_resp.status_code == 200:
                try:
                    print("Cache Miss: %s" % hostname)
                    answer = json.loads(lookup_resp.text)['Answer']
                    CACHE[hostname] = {ltype: answer, "dt": datetime.datetime.now()}
                except:
                    answer = []
            else:
                answer = []

        reply = request.reply()
        for record in answer:
            rtype = QTYPE[record['type']]
            zone = "%s %s %s %s" % (str(record['name']),
                                    record['TTL'],
                                    rtype,
                                    str(record['data']))
            reply.add_answer(*RR.fromZone(zone))

        return reply 
开发者ID:robputt796,项目名称:Py-DNS-over-HTTPS-Proxy,代码行数:54,代码来源:__init__.py


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