本文整理汇总了Python中dns.reversename.from_address方法的典型用法代码示例。如果您正苦于以下问题:Python reversename.from_address方法的具体用法?Python reversename.from_address怎么用?Python reversename.from_address使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dns.reversename
的用法示例。
在下文中一共展示了reversename.from_address方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ip2host
# 需要导入模块: from dns import reversename [as 别名]
# 或者: from dns.reversename import from_address [as 别名]
def ip2host(ip, resolver=resolver, use_tcp=False):
result = ip
try:
addr = reversename.from_address(ip)
except dns.exception.SyntaxError:
logging.warning('DNS: invalid address: %s' % ip)
return result
try:
answer = str(resolver.query(addr, 'PTR', tcp=use_tcp)[0])
result = answer.rstrip('.')
except (dns.resolver.NXDOMAIN, dns.resolver.Timeout) as e:
pass
except:
logging.warning('DNS lookup failed: %s' % addr)
pass
return result
# Translate the binary SID from LDAP into human-readable form
示例2: _reverse_lookup
# 需要导入模块: from dns import reversename [as 别名]
# 或者: from dns.reversename import from_address [as 别名]
def _reverse_lookup(ip: str) -> List[str]:
try:
address = reversename.from_address(ip).to_text()
return [rev.to_text()[:-1].lower()
for rev in resolver.query(address, 'PTR')]
except DNSException:
return []
示例3: get
# 需要导入模块: from dns import reversename [as 别名]
# 或者: from dns.reversename import from_address [as 别名]
def get(self, ip):
t1 = time.time()
self.valid_args(ip)
# Iterate through nameservers so that we can tell which one gets used.
nameservers = current_app.config['RESOLVERS']
for nameserver in nameservers:
dns_resolver.nameservers = [nameserver]
try:
# http://stackoverflow.com/a/19867936/1707152
answer = dns_resolver.query(
reversename.from_address(ip), rdatatype.PTR,
raise_on_no_answer=False)
# Successful query
break
except Timeout as e:
# Communication fail or timeout - try next nameserver
if nameserver is nameservers[-1]:
current_app.logger.info(e)
return {'message': 'All nameservers timed out.'}, 503
continue
except NXDOMAIN:
return {'message': 'No nameserver found for the provided IP'}, 404
except Exception as e:
current_app.logger.error(e)
return {'message': 'An unexpected error occured.'}, 500
t2 = time.time()
duration = t2 - t1
if answer is None:
return {'message': 'An unexpected error occured.'}, 500
return parse_query(answer, nameserver, duration)
示例4: rbl_list
# 需要导入模块: from dns import reversename [as 别名]
# 或者: from dns.reversename import from_address [as 别名]
def rbl_list(address, black_list):
""" Returns True if the list is in an rbl given at black_list.
"""
reversed_ip = from_address(address)
domain = str(reversed_ip.split(3)[0]) + '.' + black_list
try:
dns.resolver.query(domain, 'a')
except (dns.resolver.NXDOMAIN,
dns.resolver.NoNameservers,
dns.resolver.NoAnswer):
return False
return True
示例5: get_reverse
# 需要导入模块: from dns import reversename [as 别名]
# 或者: from dns.reversename import from_address [as 别名]
def get_reverse(ipaddr):
return reversename.from_address(ipaddr).to_text(omit_final_dot=True)
# noinspection PyPep8Naming
示例6: ReverseIPQuery
# 需要导入模块: from dns import reversename [as 别名]
# 或者: from dns.reversename import from_address [as 别名]
def ReverseIPQuery(value, dnsserver):
""" IP DNS Reverse lookup """
try:
revname = reversename.from_address(value)
myresolver = dns.resolver.Resolver()
myresolver.nameservers = [dnsserver]
return str(myresolver.query(revname, 'PTR')[0]).rstrip('.')
except Exception as e:
print(e)
return ''
# ########## Parse the Results to get usefull data ############## #
示例7: lookup_reverse
# 需要导入模块: from dns import reversename [as 别名]
# 或者: from dns.reversename import from_address [as 别名]
def lookup_reverse(ip_address):
"""Perform a reverse lookup of IP address."""
try:
type(ipaddress.ip_address(ip_address))
except ValueError:
return {}
record = reversename.from_address(ip_address)
hostname = str(resolver.query(record, "PTR")[0])[:-1]
return {'hostname': hostname}