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


Python reversename.from_address方法代码示例

本文整理汇总了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 
开发者ID:fox-it,项目名称:BloodHound.py,代码行数:22,代码来源:utils.py

示例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 [] 
开发者ID:PrivacyScore,项目名称:PrivacyScore,代码行数:9,代码来源:network.py

示例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) 
开发者ID:opendns,项目名称:OpenResolve,代码行数:35,代码来源:endpoints.py

示例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 
开发者ID:pygame,项目名称:pygameweb,代码行数:14,代码来源:rbl.py

示例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 
开发者ID:erigones,项目名称:esdc-ce,代码行数:6,代码来源:record.py

示例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 ############## # 
开发者ID:twelvesec,项目名称:gasmask,代码行数:15,代码来源:gasmask.py

示例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} 
开发者ID:fportantier,项目名称:habu,代码行数:12,代码来源:dns.py


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