def read_hop_info(hopinfo_path, hop_ip):
    default_hop_path = hopinfo_path + hop_ip + ".json"
    if os.path.exists(default_hop_path):
        try:
            hop_info = json.load(open(default_hop_path))
        except:
            os.remove(default_hop_path)
            if is_ip(hop_ip):
                hop_info = ipinfo(hop_ip)
                save_ipinfo(hopinfo_path, hop_info)
            else:
                hop_info = {}
    else:
        if not is_ip(hop_ip):
            hop_ip = host2ip(hop_ip)

        if is_ip(hop_ip):
            hop_info = ipinfo(hop_ip)
            save_ipinfo(hopinfo_path, hop_info)
        else:
            hop_info = {}
    return hop_info
Example #2
0
def read_hop_info(hopinfo_path, hop_ip):
    default_hop_path = hopinfo_path + hop_ip + ".json"
    if os.path.exists(default_hop_path):
        try:
            hop_info = json.load(open(default_hop_path))
        except:
            os.remove(default_hop_path)
            if is_ip(hop_ip):
                hop_info = ipinfo(hop_ip)
                save_ipinfo(hopinfo_path, hop_info)
            else:
                hop_info = {}
    else:
        if not is_ip(hop_ip):
            hop_ip = host2ip(hop_ip)

        if is_ip(hop_ip):
            hop_info = ipinfo(hop_ip)
            save_ipinfo(hopinfo_path, hop_info)
        else:
            hop_info = {}
    return hop_info
def get_ip_and_hostname(ip_or_hostname):
    ip = None
    name = None
    if is_hostname(ip_or_hostname):
        name = ip_or_hostname
        ip = host2ip(ip_or_hostname)
    elif is_ip(ip_or_hostname):
        ip = ip_or_hostname
        ip_info = ipinfo(ip_or_hostname)
        if "hostname" not in ip_info.keys():
            name = ip_or_hostname
        else:
            name = ip_info["hostname"]
            if '.' not in name:
                name = ip_or_hostname
    else:
        print "[Error] Input argument in function get_ip_and_hostname(): ", ip_or_hostname, " is neither an ip nor a hostname!"
        exit(-1)

    return ip, name
Example #4
0
def get_ip_and_hostname(ip_or_hostname):
    ip = None
    name = None
    if is_hostname(ip_or_hostname):
        name = ip_or_hostname
        ip = host2ip(ip_or_hostname)
    elif is_ip(ip_or_hostname):
        ip = ip_or_hostname
        ip_info = ipinfo(ip_or_hostname)
        if "hostname" not in ip_info.keys():
            name = ip_or_hostname
        else:
            name = ip_info["hostname"]
            if '.' not in name:
                name = ip_or_hostname
    else:
        print "[Error] Input argument in function get_ip_and_hostname(): ", ip_or_hostname, " is neither an ip nor a hostname!"
        exit(-1)

    return ip, name