当前位置: 首页>>代码示例>>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;未经允许,请勿转载。