ip.py 文件源码

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

项目:charm-heat 作者: openstack 项目源码 文件源码
def get_host_ip(hostname, fallback=None):
    """
    Resolves the IP for a given hostname, or returns
    the input if it is already an IP.
    """
    if is_ip(hostname):
        return hostname

    ip_addr = ns_query(hostname)
    if not ip_addr:
        try:
            ip_addr = socket.gethostbyname(hostname)
        except Exception:
            log("Failed to resolve hostname '%s'" % (hostname),
                level=WARNING)
            return fallback
    return ip_addr
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号