當前位置: 首頁>>代碼示例>>Python>>正文


Python DNSRecord.parse方法代碼示例

本文整理匯總了Python中dnslib.DNSRecord.parse方法的典型用法代碼示例。如果您正苦於以下問題:Python DNSRecord.parse方法的具體用法?Python DNSRecord.parse怎麽用?Python DNSRecord.parse使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在dnslib.DNSRecord的用法示例。


在下文中一共展示了DNSRecord.parse方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_reply

# 需要導入模塊: from dnslib import DNSRecord [as 別名]
# 或者: from dnslib.DNSRecord import parse [as 別名]
def get_reply(self,data):
        request = DNSRecord.parse(data)
        self.server.logger.log_request(self,request)

        resolver = self.server.resolver
        reply = resolver.resolve(request,self)
        self.server.logger.log_reply(self,reply)

        if self.protocol == 'udp':
            rdata = reply.pack()
            if self.udplen and len(rdata) > self.udplen:
                truncated_reply = reply.truncate()
                rdata = truncated_reply.pack()
                self.server.logger.log_truncated(self,truncated_reply)
        else:
            rdata = reply.pack()

        return rdata 
開發者ID:Macronut,項目名稱:Proxy46,代碼行數:20,代碼來源:server.py

示例2: get_reply

# 需要導入模塊: from dnslib import DNSRecord [as 別名]
# 或者: from dnslib.DNSRecord import parse [as 別名]
def get_reply(self,data):
        host,port = self.server.resolver.address,self.server.resolver.port

        request = DNSRecord.parse(data)
        self.log_request(request)

        if self.protocol == 'tcp':
            data = struct.pack("!H",len(data)) + data
            response = send_tcp(data,host,port)
            response = response[2:]
        else:
            response = send_udp(data,host,port)

        reply = DNSRecord.parse(response)
        self.log_reply(reply)

        return response 
開發者ID:yuxiaokui,項目名稱:Intranet-Penetration,代碼行數:19,代碼來源:proxy.py

示例3: resolve

# 需要導入模塊: from dnslib import DNSRecord [as 別名]
# 或者: from dnslib.DNSRecord import parse [as 別名]
def resolve(self,request,handler):
        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) and (qtype in (rtype,'ANY','CNAME')):
                    a = copy.copy(rr)
                    a.rname = qname
                    reply.add_answer(a)
        # Check for NXDOMAIN
        if any([qname.matchGlob(s) for s in self.nxdomain]):
            reply.header.rcode = getattr(RCODE,'NXDOMAIN')
            return reply
        # Otherwise proxy
        if not reply.rr:
            if handler.protocol == 'udp':
                proxy_r = request.send(self.address,self.port)
            else:
                proxy_r = request.send(self.address,self.port,tcp=True)
            reply = DNSRecord.parse(proxy_r)
        return reply 
開發者ID:yuxiaokui,項目名稱:Intranet-Penetration,代碼行數:25,代碼來源:intercept.py

示例4: resolve

# 需要導入模塊: from dnslib import DNSRecord [as 別名]
# 或者: from dnslib.DNSRecord import parse [as 別名]
def resolve(self,request,handler):
        reply = request.reply()
        qname = request.q.qname
        qtype = QTYPE[request.q.qtype]
        if qname.matchGlob("api-*padsv.gungho.jp."):
            config = wx.ConfigBase.Get()
            host = config.Read("host") or socket.gethostbyname(socket.gethostname())
            reply.add_answer(RR(qname,QTYPE.A,rdata=A(host)))
            evt = custom_events.wxStatusEvent(message="Got DNS Request")
            wx.PostEvent(self.status_ctrl,evt)
            evt = custom_events.wxDNSEvent(message=str(qname)[:-1])
            wx.PostEvent(self.main_frame,evt)
            time.sleep(0.5) # we need to sleep until the proxy is up, half a second should do it...
        # Otherwise proxy
        if not reply.rr:
            if handler.protocol == 'udp':
                proxy_r = request.send(self.address,self.port)
            else:
                proxy_r = request.send(self.address,self.port,tcp=True)
            reply = DNSRecord.parse(proxy_r)
        return reply 
開發者ID:jgoldshlag,項目名稱:padherder_proxy,代碼行數:23,代碼來源:dnsproxy.py

示例5: default

# 需要導入模塊: from dnslib import DNSRecord [as 別名]
# 或者: from dnslib.DNSRecord import parse [as 別名]
def default(self, request, server):
        proxy_r = request.send(self.address,self.port,tcp=False,timeout=self.timeout)
        return DNSRecord.parse(proxy_r) 
開發者ID:Macronut,項目名稱:Proxy46,代碼行數:5,代碼來源:proxy.py

示例6: default6

# 需要導入模塊: from dnslib import DNSRecord [as 別名]
# 或者: from dnslib.DNSRecord import parse [as 別名]
def default6(self, request, server):
        v6enable = server[1].find('.') == -1
        proxy_r = request.send(server[1][0], server[1][1], tcp=False, timeout=self.timeout, ipv6=v6enable)
        return DNSRecord.parse(proxy_r) 
開發者ID:Macronut,項目名稱:Proxy46,代碼行數:6,代碼來源:proxy.py

示例7: cache

# 需要導入模塊: from dnslib import DNSRecord [as 別名]
# 或者: from dnslib.DNSRecord import parse [as 別名]
def cache(self, request, server):
        v6enable = server[1][0].find('.') == -1
        tcpenable = server[1][0] == '8.8.4.4'
        proxy_r = request.send(server[1][0],server[1][1],tcp=tcpenable,timeout=self.timeout,ipv6=v6enable)
        reply = DNSRecord.parse(proxy_r)
        save_cache(server, str(request.q.qname)[:-1], reply)
        return reply 
開發者ID:Macronut,項目名稱:Proxy46,代碼行數:9,代碼來源:proxy.py

示例8: resolve

# 需要導入模塊: from dnslib import DNSRecord [as 別名]
# 或者: from dnslib.DNSRecord import parse [as 別名]
def resolve(self,request,handler):
        if handler.protocol == 'udp':
            proxy_r = request.send(self.address,self.port)
        else:
            proxy_r = request.send(self.address,self.port,tcp=True)
        reply = DNSRecord.parse(proxy_r)
        return reply 
開發者ID:yuxiaokui,項目名稱:Intranet-Penetration,代碼行數:9,代碼來源:proxy.py

示例9: handle_server_reply

# 需要導入模塊: from dnslib import DNSRecord [as 別名]
# 或者: from dnslib.DNSRecord import parse [as 別名]
def handle_server_reply(self, data, addr):
        try:
            reply = DNSRecord.parse(data)
        except Exception as e:
            logging.error(e)
            return

        logging.info("reply for {} from {}".format(reply.q.qname, addr))

        if (reply.header.id, addr) in self.waiting:
            info = self.waiting.pop((reply.header.id, addr))
            if reply.header.rcode == RCODE.SERVFAIL:
                logging.warning("{} sends SERVFAIL".format(addr))
                resp = self.load_from_cache_failed(info[0])
                if resp:
                    reply = resp
            reply.header.id = info[4]
            self.send_reply_to(reply, info[1])
            # only cache NOERROR and NXDOMAIN results
            if reply.header.rcode in (RCODE.NOERROR, RCODE.NXDOMAIN):
                dumped = pickle.dumps(reply)
                key = "dns-fail:{}:{}".format(info[0].q.qname, info[0].q.qtype)
                logging.debug("add {} to cache, ttl={}".format(key, self.max_cache_ttl))
                self.redis.set(key, dumped, ex=self.max_cache_ttl)
                if info[3] > 0:
                    #only cache if TTL in config > 0
                    key = "dns:{}:{}".format(info[0].q.qname, info[0].q.qtype)
                    logging.debug("add {} to cache, ttl={}".format(key, info[3]))
                    self.redis.set(key, dumped, ex=info[3]) 
開發者ID:jimzhong,項目名稱:zjudns,代碼行數:31,代碼來源:forwarder.py

示例10: resolve

# 需要導入模塊: from dnslib import DNSRecord [as 別名]
# 或者: from dnslib.DNSRecord import parse [as 別名]
def resolve(self,request,handler):
        try:
            if handler.protocol == 'udp':
                proxy_r = request.send(self.address,self.port,
                                timeout=self.timeout)
            else:
                proxy_r = request.send(self.address,self.port,
                                tcp=True,timeout=self.timeout)
            reply = DNSRecord.parse(proxy_r)
        except socket.timeout:
            reply = request.reply()
            reply.header.rcode = getattr(RCODE,'NXDOMAIN')

        return reply 
開發者ID:Dylan-halls,項目名稱:Theseus,代碼行數:16,代碼來源:proxy.py

示例11: resolve

# 需要導入模塊: from dnslib import DNSRecord [as 別名]
# 或者: from dnslib.DNSRecord import parse [as 別名]
def resolve(self,request,handler):
        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) and (qtype in (rtype,'ANY','CNAME')):
                    a = copy.copy(rr)
                    a.rname = qname
                    reply.add_answer(a)
        # Check for NXDOMAIN
        if any([qname.matchGlob(s) for s in self.nxdomain]):
            reply.header.rcode = getattr(RCODE,'NXDOMAIN')
            return reply
        # Otherwise proxy
        if not reply.rr:
            try:
                if handler.protocol == 'udp':
                    proxy_r = request.send(self.address,self.port,
                                    timeout=self.timeout)
                else:
                    proxy_r = request.send(self.address,self.port,
                                    tcp=True,timeout=self.timeout)
                reply = DNSRecord.parse(proxy_r)
            except socket.timeout:
                reply.header.rcode = getattr(RCODE,'NXDOMAIN')

        return reply 
開發者ID:Dylan-halls,項目名稱:Theseus,代碼行數:31,代碼來源:intercept.py

示例12: parse

# 需要導入模塊: from dnslib import DNSRecord [as 別名]
# 或者: from dnslib.DNSRecord import parse [as 別名]
def parse():
        import argparse
        parser = argparse.ArgumentParser(prog=PROJ,
                                         description='A simple dns router', formatter_class=argparse.RawTextHelpFormatter)
        parser.add_argument('-v', '--version', action='version', version='%(prog)s 0.2a')
        parser.add_argument('-c', '--config', dest='config', default=os.path.join(os.path.dirname(__file__), PROJ + '.yml'), help='specify the config file, default: ' + PROJ + '.yml')
        parser.add_argument('-t', '--test', dest='test', action='store_true', help='test the format of the config file')
        ArgumentParser.args = parser.parse_args().__dict__ 
開發者ID:Major1201,項目名稱:dns-router,代碼行數:10,代碼來源:dns-router.py

示例13: main

# 需要導入模塊: from dnslib import DNSRecord [as 別名]
# 或者: from dnslib.DNSRecord import parse [as 別名]
def main():
    # parse argument
    ArgumentParser.parse()

    # init setting
    from utils import setting
    with open(ArgumentParser.args['config']) as _f:
        setting.load(_f)

    # init logger
    from utils import logger
    logger.initialize()

    # check config
    if ArgumentParser.args['test']:
        ConfigParser(setting.conf).check()
        logger.info('Test successfully, ' + str(len(setting.conf.get('dns_servers', []))) + ' server(s) found.')
        sys.exit()

    pid_file = os.path.join(os.path.dirname(__file__), setting.conf.get('system').get('project_name') + '.pid')
    with DnsRouter(pid_file):
        # signal
        from utils import system
        if os.name == 'posix':
            system.register_sighandler(DNSServerLoader.stop, 2, 3, 15)
            system.register_sighandler(DNSServerLoader.reload, 10)
        else:
            system.register_sighandler(DNSServerLoader.stop, 2, 15)
        try:
            # start server threads
            DNSServerLoader.daemon()
        except IOError as e:
            import errno
            # skip Interrupted function call in Windows
            if e.errno != errno.EINTR:
                raise 
開發者ID:Major1201,項目名稱:dns-router,代碼行數:38,代碼來源:dns-router.py

示例14: map46

# 需要導入模塊: from dnslib import DNSRecord [as 別名]
# 或者: from dnslib.DNSRecord import parse [as 別名]
def map46(self, request, server):
        v6enable = server[1][0].find('.') == -1
        request.q.qtype = DNS_AAAA_RECORD
        temp_proxy_r = request.send(server[1][0], server[1][1], timeout=self.timeout, ipv6=v6enable)
        temp_reply = DNSRecord.parse(temp_proxy_r)
        iplist = map_ip(server, str(request.q.qname)[:-1], temp_reply)
        request.q.qtype = DNS_A_RECORD
        reply = request.reply()
        for ip in iplist:
            reply.add_answer(RR(rname=request.q.qname, rtype=request.q.qtype, rclass=1, ttl=TTL, rdata=A(ip)))
        return reply 
開發者ID:Macronut,項目名稱:Proxy46,代碼行數:13,代碼來源:proxy.py

示例15: handle_client_request

# 需要導入模塊: from dnslib import DNSRecord [as 別名]
# 或者: from dnslib.DNSRecord import parse [as 別名]
def handle_client_request(self, data, addr):
        try:
            request = DNSRecord.parse(data)
        except Exception as e:
            logging.error(e)
            return

        logging.info("request for {} from {}".format(request.q.qname, addr))

        if request.q.qtype not in self.allowed_qtype:
            logging.info("not allowed qtype of {}".format(request.q.qtype))
            reply = request.reply()
            reply.header.rcode = RCODE.REFUSED
            self.send_reply_to(reply, addr)
            return

        if request.q.qtype == QTYPE.A:
            reply = self.load_from_hosts(request)
            if reply:
                logging.info("found {} in hosts".format(request.q.qname))
                self.send_reply_to(reply, addr)
                return

        cached = self.load_from_cache(request)
        if cached:
            # TODO: Add TTL adjustment
            logging.info("cache hit on {}".format(request.q.qname))
            self.send_reply_to(cached, addr)
            return

        #Do actual query based on qname
        try:
            upstream_name = self.match_domain_in_dict(request.q.qname.label, self.domains)
            if upstream_name is None:
                logging.debug("resolve {} from default server".format(request.q.qname))
                self.send_to_upstream(request, 'default', addr)
            else:
                logging.debug("resolve {} from {}".format(request.q.qname, upstream_name))
                self.send_to_upstream(request, upstream_name, addr)
        except Exception as e:
            logging.error(e)
            reply = request.reply()
            reply.header.rcode = RCODE.SERVFAIL
            self.send_reply_to(reply, addr) 
開發者ID:jimzhong,項目名稱:zjudns,代碼行數:46,代碼來源:forwarder.py


注:本文中的dnslib.DNSRecord.parse方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。