本文整理汇总了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
示例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))
示例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
示例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))
示例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,
}
示例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
示例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))
示例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)
示例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)
示例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)
示例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
示例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
示例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
示例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,
}
示例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