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


Python Resolver.nameservers方法代码示例

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


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

示例1: connect

# 需要导入模块: from dns.resolver import Resolver [as 别名]
# 或者: from dns.resolver.Resolver import nameservers [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

示例2: resolve

# 需要导入模块: from dns.resolver import Resolver [as 别名]
# 或者: from dns.resolver.Resolver import nameservers [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

示例3: check_dns

# 需要导入模块: from dns.resolver import Resolver [as 别名]
# 或者: from dns.resolver.Resolver import nameservers [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

示例4: connect

# 需要导入模块: from dns.resolver import Resolver [as 别名]
# 或者: from dns.resolver.Resolver import nameservers [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

示例5: reverse_dns_lookup

# 需要导入模块: from dns.resolver import Resolver [as 别名]
# 或者: from dns.resolver.Resolver import nameservers [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

示例6: make_client

# 需要导入模块: from dns.resolver import Resolver [as 别名]
# 或者: from dns.resolver.Resolver import nameservers [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

示例7: connect

# 需要导入模块: from dns.resolver import Resolver [as 别名]
# 或者: from dns.resolver.Resolver import nameservers [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

示例8: test_raise_dns_tcp

# 需要导入模块: from dns.resolver import Resolver [as 别名]
# 或者: from dns.resolver.Resolver import nameservers [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

示例9: test_noraise_dns_tcp

# 需要导入模块: from dns.resolver import Resolver [as 别名]
# 或者: from dns.resolver.Resolver import nameservers [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

示例10: get_ip

# 需要导入模块: from dns.resolver import Resolver [as 别名]
# 或者: from dns.resolver.Resolver import nameservers [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

示例11: get_nsset

# 需要导入模块: from dns.resolver import Resolver [as 别名]
# 或者: from dns.resolver.Resolver import nameservers [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

示例12: resolve_a_record

# 需要导入模块: from dns.resolver import Resolver [as 别名]
# 或者: from dns.resolver.Resolver import nameservers [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

示例13: get_record_ttl

# 需要导入模块: from dns.resolver import Resolver [as 别名]
# 或者: from dns.resolver.Resolver import nameservers [as 别名]
def get_record_ttl(record, nameservers=GOOGLE_NAMESERVERS):
    """This function returns the TTL of a record after it resolved it using a
    DNS resolver.

    :param record: the record to resolve

    :returns: the TTL of the record
    """
    ttl = False
    # try:
    resolver = Resolver(configure=False)
    resolver.nameservers = nameservers
    resolution = resolver.query(record)
    ttl = resolution.rrset.ttl
    # except:
    #     pass

    return ttl
开发者ID:EnlightNS,项目名称:enlightns-cli,代码行数:20,代码来源:resolver.py

示例14: dns6_lookup

# 需要导入模块: from dns.resolver import Resolver [as 别名]
# 或者: from dns.resolver.Resolver import nameservers [as 别名]
def dns6_lookup(input, timeout=3, server=''):
    """Perform a simple DNS lookup, return results in a dictionary"""
    resolver = Resolver()
    resolver.timeout = float(timeout)
    resolver.lifetime = float(timeout)
    if server:
        resolver.nameservers = [server]
    try:
        records = resolver.query(input, 'AAAA')
        return {'addrs': [ii.address for ii in records],
            'error': '',
            'name': input,
            }
    except DNSException as e:
        return {'addrs': [], 
            'error': repr(e),
            'name': input,
            }
开发者ID:richardstrnad,项目名称:ciscoconfparse,代码行数:20,代码来源:ccp_util.py

示例15: check_dns

# 需要导入模块: from dns.resolver import Resolver [as 别名]
# 或者: from dns.resolver.Resolver import nameservers [as 别名]
def check_dns(check, data):
	check.addOutput("ScoreEngine: {} Check\n".format(check.getServiceName()))
	check.addOutput("EXPECTED: Sucessful and correct query against the DNS server")
	check.addOutput("OUTPUT:\n")

	# Setup the resolver
	resolv = Resolver()
	resolv.nameservers = [data["HOST"]]
	resolv.timeout = dns_config["timeout"]
	resolv.lifetime = dns_config["lifetime"]

	check.addOutput("Starting check...")

	try:
		# Query resolver
		check.addOutput("Querying {HOST} for '{LOOKUP}'...".format(**data))
		lookup = resolv.query(data["LOOKUP"], data["TYPE"])

		found = False
		for ans in lookup:
			if str(ans) == data["EXPECTED"]:
				found = True
			else:
				check.addOutput("NOTICE: DNS Server returned {}".format(ans))

		if not found:
			check.addOutput("ERROR: DNS Server did not respond with the correct IP")
			return

		# We're good!
		check.setPassed()
		check.addOutput("Check successful!")
	except Exception as e:
		check.addOutput("ERROR: {}: {}".format(type(e).__name__, e))

		return
开发者ID:ubnetdef,项目名称:scoreengine,代码行数:38,代码来源:dns.py


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