utils.py 文件源码

python
阅读 18 收藏 0 点赞 0 评论 0

项目:cerberus-core 作者: ovh 项目源码 文件源码
def get_ip_network(ip_str):
    """
        Try to return the owner of the IP address (based on ips.py)

        :param str ip_str: The IP address
        :rtype: str
        :return: The owner if find else None
    """
    try:
        ip_addr = netaddr.IPAddress(ip_str)
    except (netaddr.AddrConversionError, netaddr.AddrFormatError):
        return None

    for brand, networks in IPS_NETWORKS.iteritems():
        for net in networks:
            if net.netmask.value & ip_addr.value == net.value:
                return brand
    return None
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号