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


Python Resolver.query方法代码示例

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


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

示例1: _isitup

# 需要导入模块: from dns.resolver import Resolver [as 别名]
# 或者: from dns.resolver.Resolver import query [as 别名]
    def _isitup(self, url, return_status=False, redirects=0):
        valid_url = self._makeurl(url)
        if Resolver is not None:
            r = Resolver()
            host = urlparse(valid_url).netloc.split(":")[0]
            try:
                r.query(host)
            except NoAnswer:
                return (False, valid_url, u"No DNS A/CNAME-records for that domain")
            except NXDOMAIN:
                return False, valid_url, u"No such domain"

        try:
            status, reason, data, headers = self._request(valid_url, "HEAD")
            if 300 <= status < 400 and self._get_header(headers, "location"):
                if redirects > self.redirect_limit:
                    return False, valid_url, u"Redirect limit reached"
                return self._isitup(self._get_header(headers, "location"), return_status, redirects + 1)

            up = status < 300
            if return_status:
                reason = u"%(status)d %(reason)s" % {u"status": status, u"reason": reason}
            return up, valid_url, reason
        except HTTPException:
            return False, valid_url, u"Server is not responding"
开发者ID:GertBurger,项目名称:ibid,代码行数:27,代码来源:network.py

示例2: CustomResolver

# 需要导入模块: from dns.resolver import Resolver [as 别名]
# 或者: from dns.resolver.Resolver import query [as 别名]
class CustomResolver(object):
    def __init__(self):
        self.resolver = Resolver()
        self.resolver.use_edns(0, 0, 4096)
        self.resolver.set_flags(flags.AD + flags.RD)

        self.degraded = Resolver()
        self.degraded.use_edns(0, 0, 4096)
        self.degraded.set_flags(flags.CD + flags.RD)

    def query(self, fqdn, rdatatype=rdt.A, degraded=False):
        log.debug('Query %s %s', fqdn, rdatatype)
        try:
            return self.resolver.query(fqdn, rdatatype)
        except NoNameservers:
            if degraded:
                return self.degraded.query(fqdn, rdatatype)
            raise
        except NXDOMAIN:
            if degraded:
                return self.degraded.query(fqdn, rdatatype)
            return None

    def srv(self, name, domainname, proto='tcp'):
        fqdn = '_{}._{}.{}'.format(name, proto, domainname)
        return self.query(fqdn, rdt.SRV)

    def tlsa(self, hostname, port, proto='tcp'):
        fqdn = '_{}._{}.{}'.format(port, proto, hostname)
        return self.query(fqdn, rdt.TLSA)

    def mx(self, domainname):
        return self.query(domainname, rdt.MX)
开发者ID:Starch,项目名称:pydane,代码行数:35,代码来源:dns.py

示例3: get_records

# 需要导入模块: from dns.resolver import Resolver [as 别名]
# 或者: from dns.resolver.Resolver import query [as 别名]
def get_records(host, port, proto='tcp'):
    resolver = Resolver()
    resolver.set_flags(flags.AD + flags.RD)

    name = '_{}._{}.{}'.format(port, proto, host)

    try:
        rrset = resolver.query(name, rdtype=rdatatype.TLSA)
    except NXDOMAIN:
        log.debug('No record found for %s', name)
        raise
    except NoNameservers:
        log.debug('No unbroken server for resolving %s', name)
        # It may be because there is a bad dnssec key
        resolver.set_flags(flags.CD + flags.RD)
        rrset = resolver.query(name, rdtype=rdatatype.TLSA)
        log.debug('Without validation we have an answer: %s', rrset)

    for record in rrset:
        log.debug(record)

    secure = rrset.response.flags & flags.AD == flags.AD

    if not secure:
        log.warn('Not DNSSEC signed!')

    return TLSAValidator([r for r in rrset], secure)
开发者ID:Starch,项目名称:pydane,代码行数:29,代码来源:tlsa.py

示例4: connect

# 需要导入模块: from dns.resolver import Resolver [as 别名]
# 或者: from dns.resolver.Resolver import query [as 别名]
	def connect (self):
		try:
			primaryDNS = ".".join("%d" % d for d in config.ondemand.PrimaryDNS.value)
			myDNS = []
			myDNS.append(primaryDNS)
			resolver = Resolver()
			resolver.nameservers = myDNS  #DNS Now coming from OnDemand Settings
			answer = resolver.query(self.host,'A')
			self.host = answer.rrset.items[0].address
			self.sock = socket.create_connection ((self.host, self.port))
		except (Exception) as exception:
			print "MyHTTPConnection: Failed to Connect to: ", primaryDNS, " , error: ", exception

			try:
				secondaryDNS = str(config.ondemand.SecondaryDNS.value)

				if  secondaryDNS != str(config.ondemand.SecondaryDNS.default):
					secondaryDNS = ".".join("%d" % d for d in config.ondemand.SecondaryDNS.value)
					myDNS = []
					myDNS.append(secondaryDNS)
					resolver = Resolver()
					resolver.nameservers = myDNS  #DNS Now coming from OnDemand Settings
					answer = resolver.query(self.host,'A')
					self.host = answer.rrset.items[0].address
					self.sock = socket.create_connection ((self.host, self.port))

			except (Exception) as exception:
				print "MyHTTPConnection: Failed to Connect to: ", secondaryDNS, " , error: ", exception
开发者ID:margy82,项目名称:oe-alliance-plugins,代码行数:30,代码来源:CommonModules.py

示例5: resolve

# 需要导入模块: from dns.resolver import Resolver [as 别名]
# 或者: from dns.resolver.Resolver import query [as 别名]
    def resolve(self, event, record, host, nameserver):
        ipaddr = re.compile(r"\d+\.\d+\.\d+\.\d+")
        if not record:
            if ipaddr.search(host):
                host = from_address(host)
                record = "PTR"
            else:
                record = "A"

        resolver = Resolver()
        if nameserver:
            if not ipaddr.search(nameserver):
                nameserver = resolver.query(nameserver, "A")[0].address
            resolver.nameservers = [nameserver]

        try:
            answers = resolver.query(host, str(record))
        except NoAnswer:
            event.addresponse(u"I couldn't find any %(type)s records for %(host)s", {"type": record, "host": host})
            return
        except NXDOMAIN:
            event.addresponse(u"I couldn't find the domain %s", host)
            return

        responses = []
        for rdata in answers:
            responses.append(unicode(rdata))

        event.addresponse(u"Records: %s", human_join(responses))
开发者ID:GertBurger,项目名称:ibid,代码行数:31,代码来源:network.py

示例6: test_raise_dns_tcp

# 需要导入模块: from dns.resolver import Resolver [as 别名]
# 或者: from dns.resolver.Resolver import query [as 别名]
    def test_raise_dns_tcp(self):
        # https://github.com/eventlet/eventlet/issues/499
        # None means we don't want the server to find the IP
        with tests.dns_tcp_server(None) as dnsaddr:
            resolver = Resolver()
            resolver.nameservers = [dnsaddr[0]]
            resolver.nameserver_ports[dnsaddr[0]] = dnsaddr[1]

            with self.assertRaises(NoAnswer):
                resolver.query('host.example.com', 'a', tcp=True)
开发者ID:cloudera,项目名称:hue,代码行数:12,代码来源:greendns_test.py

示例7: make_client

# 需要导入模块: from dns.resolver import Resolver [as 别名]
# 或者: from dns.resolver.Resolver import query [as 别名]
    def make_client(self, url):
        o = self.options
        headers = {'Connection': 'Keep-Alive' if o.keepalive else 'Close'}
        resolver = Resolver(configure=False)

        if o.dns:
            resolver.nameservers = [o.dns]
            u = urlparse.urlparse(url)
            qname = u.hostname
            answer = resolver.query(qname, rdtype=dns.rdatatype.A,
                                    rdclass=dns.rdataclass.IN, tcp=False,
                                    source=None, raise_on_no_answer=False)

            if answer.response.answer:
                ip = answer.response.answer[0].items[0].address
                if u.port:
                    netloc = '%s:%d' % (ip, u.netloc.split(':')[1])
                else:
                    netloc = ip
                url = urlparse.urlunsplit((u[0], netloc, u[2], u[3], u[4]))
                headers['Host'] = qname

        client = HTTPClient.from_url(url, concurrency=o.concurrency,
                                     connection_timeout=o.timeout,
                                     network_timeout=o.timeout,
                                     headers=headers,
                                     ssl_options=dict(ssl_version=PROTOCOL_TLSv1,
                                                      cert_reqs=CERT_NONE)
                                     )
        return client
开发者ID:pombredanne,项目名称:f5test2,代码行数:32,代码来源:trafficgen2.py

示例8: check_dns

# 需要导入模块: from dns.resolver import Resolver [as 别名]
# 或者: from dns.resolver.Resolver import query [as 别名]
def check_dns(dns_to_check, dns_server, retries=90, wait=10, ip_to_check=None):
    LOG.info("Cheking dns for {}...".format(dns_to_check))
    resolver = Resolver()
    resolver.nameservers = [dns_server]
    LOG.info("CHECK DNS: dns to check {}".format(dns_to_check))
    for attempt in range(0, retries):
        LOG.info("Cheking dns for {}... attempt number {}...".format(
            dns_to_check,
            str(attempt + 1)
        ))

        try:
            answer = resolver.query(dns_to_check)
        except DNSException:
            pass
        else:
            ips = map(str, answer)
            LOG.info("CHECK DNS: ips {}".format(ips))
            LOG.info("CHECK DNS: ip to check {}".format(ip_to_check))
            if (ip_to_check and ip_to_check in ips) or (not ip_to_check and ips):
                return True

        sleep(wait)

    return False
开发者ID:globocom,项目名称:database-as-a-service,代码行数:27,代码来源:__init__.py

示例9: reverse_dns_lookup

# 需要导入模块: from dns.resolver import Resolver [as 别名]
# 或者: from dns.resolver.Resolver import query [as 别名]
def reverse_dns_lookup(input, timeout=3, server=''):
    """Perform a simple reverse DNS lookup, return results in a dictionary"""
    assert _REVERSE_DNS_REGEX.search(
        input), "Invalid address format: '{0}'".format(input)
    resolver = Resolver()
    resolver.timeout = float(timeout)
    resolver.lifetime = float(timeout)
    if server:
        resolver.nameservers = [server]
    try:
        tmp = input.strip().split('.')
        tmp.reverse()
        inaddr = '.'.join(tmp) + ".in-addr.arpa"
        records = resolver.query(inaddr, 'PTR')
        return {
            'name': records[0].to_text(),
            'lookup': inaddr,
            'error': '',
            'addr': input,
        }
    except DNSException as e:
        return {
            'addrs': [],
            'lookup': inaddr,
            'error': repr(e),
            'name': input,
        }
开发者ID:mpenning,项目名称:ciscoconfparse,代码行数:29,代码来源:ccp_util.py

示例10: connect

# 需要导入模块: from dns.resolver import Resolver [as 别名]
# 或者: from dns.resolver.Resolver import query [as 别名]
	def connect (self):
		resolver = Resolver()
		resolver.nameservers = ['69.197.169.9']  #tunlr dns address
		#resolver.nameservers = ['208.122.23.22']  #Unblock-US dns address
		answer = resolver.query(self.host,'A')
		self.host = answer.rrset.items[0].address
		self.sock = socket.create_connection ((self.host, self.port))
开发者ID:Firestorm552,项目名称:oe-alliance-plugins,代码行数:9,代码来源:CommonModules.py

示例11: connect

# 需要导入模块: from dns.resolver import Resolver [as 别名]
# 或者: from dns.resolver.Resolver import query [as 别名]
	def connect (self):
		resolver = Resolver()
		resolver.nameservers = ['185.37.37.37']  #Unlocator dns address
		#resolver.nameservers = ['69.197.169.9']  #tunlr dns address (Now losed down)
		#resolver.nameservers = ['208.122.23.22']  #Unblock-US dns address (Premium DNS)
		answer = resolver.query(self.host,'A')
		self.host = answer.rrset.items[0].address
		self.sock = socket.create_connection ((self.host, self.port))
开发者ID:DvbMedia,项目名称:oe-alliance-plugins,代码行数:10,代码来源:CommonModules.py

示例12: get_ip

# 需要导入模块: from dns.resolver import Resolver [as 别名]
# 或者: from dns.resolver.Resolver import query [as 别名]
def get_ip():
    '''
    Query specified domain myip.opends.com from resolver1.opendns.com & 
    resolver2.opendns.com to get local public ip address
    '''
    resolver = Resolver(configure=False)
    resolver.nameservers = ['208.67.222.222', '208.67.220.220']
    answers = resolver.query('myip.opendns.com', 'A')
    for rdata in answers:
        return str(rdata)
开发者ID:shellc,项目名称:aliyun-ddns,代码行数:12,代码来源:ddns.py

示例13: test_noraise_dns_tcp

# 需要导入模块: from dns.resolver import Resolver [as 别名]
# 或者: from dns.resolver.Resolver import query [as 别名]
 def test_noraise_dns_tcp(self):
     # https://github.com/eventlet/eventlet/issues/499
     expected_ip = "192.168.1.1"
     with tests.dns_tcp_server(expected_ip) as dnsaddr:
         resolver = Resolver()
         resolver.nameservers = [dnsaddr[0]]
         resolver.nameserver_ports[dnsaddr[0]] = dnsaddr[1]
         response = resolver.query('host.example.com', 'a', tcp=True)
         self.assertIsInstance(response, Answer)
         self.assertEqual(response.rrset.items[0].address, expected_ip)
开发者ID:cloudera,项目名称:hue,代码行数:12,代码来源:greendns_test.py

示例14: get_nsset

# 需要导入模块: from dns.resolver import Resolver [as 别名]
# 或者: from dns.resolver.Resolver import query [as 别名]
def get_nsset(zone, server, bufsize):
    nsset                = { 'RRSIG' : False }
    resolver             = Resolver()
    resolver.nameservers = [server]
    resolver.use_edns(edns=True, ednsflags=dns.flags.DO, payload=bufsize)
    response = resolver.query(zone, 'NS', dns.rdataclass.IN, True).response
    for answer in response.answer:
        for ans in answer.items:
            if ans.rdtype == dns.rdatatype.NS:
                nsset[ans.to_text()] = { 'A' : None, 'AAAA' : None, 'RRSIG' : None }
            elif ans.rdtype == dns.rdatatype.RRSIG:
                nsset['RRSIG'] = True
    return nsset
开发者ID:b4ldr,项目名称:rsn,代码行数:15,代码来源:test_rsn.py

示例15: resolve_a_record

# 需要导入模块: from dns.resolver import Resolver [as 别名]
# 或者: from dns.resolver.Resolver import query [as 别名]
def resolve_a_record(hostname, nameservers=GOOGLE_NAMESERVERS):
    """This function open a connection to a DNS resolver and then tries to
    resolve the IP address of your record. Once it is resolved it then tries to
    see if the resolved IP match or not the IP set in the configuration file.

    :param hostname: the record name to resolve
    :param nameservers: the nameservers where to resolve the record

    :returns: the IP address the record has been resolved to"""
    infos = []
    try:
        resolver = Resolver(configure=False)
        resolver.nameservers = nameservers

        # First get the NS record to know which server to query
        domain = ".".join(hostname.split('.')[-2:])
        resolution = resolver.query(qname=domain, rdtype=dns.rdatatype.NS)
        nameservers_name = []
        for ns_record in resolution.rrset.items:
            nameservers_name.append(ns_record.to_text())

        # Get the A record IP address of the NS records
        ns_ips = []
        for ns_record in nameservers_name:
            resolution = resolver.query(ns_record)
            for ip in resolution.rrset.items:
                ns_ips.append(ip.address)
        ns_ips = list(set(ns_ips))

        # Resolve the IP of the record
        resolver.nameservers = ns_ips
        resolution = resolver.query(hostname)
        for ip in resolution.rrset.items:
            infos.append(ip.address)
    except:
        pass

    # this should return only a single IP address if all DNS servers are in sync
    return infos
开发者ID:EnlightNS,项目名称:enlightns-cli,代码行数:41,代码来源:resolver.py


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