コード例 #1
0
ファイル: tracert.py プロジェクト: oneyoung/toy-python
def tracert(host):
    cmd = "traceroute %s" % host
    regexp = re.compile(r".*\(([0-9.]+)\).*")
    p = os.popen(cmd)
    line = p.readline()
    while line:
        m = regexp.match(line)
        if m:
            ip = m.group(1)
            line = line.strip() + "\t" + ip_location(ip) + '\n'
        print(line, end="")
        line = p.readline()
コード例 #2
0
ファイル: dns_query.py プロジェクト: oneyoung/toy-python
def build_list(hostname, dns_list):
    reg_exp = re.compile("\d+.\d+.\d+.\d+")
    print(hostname)
    ips = map(lambda s: query_host(hostname, s), filter(lambda s: reg_exp.search(s), dns_list))
    ip_set = frozenset(filter(None, ips))  # remove empty and the same IP
    pings = map(get_avr_ping, ip_set)
    result = list(zip(ip_set, pings))  # result format: [ip, ping]
    result.sort(key=lambda s: s[1])  # sort the result
    INFO('#' * 20)
    for each in result:
        print("{ip}\t{time} ms\t{loc}".format(ip=each[0], time=each[1], loc=ip_location(each[0])))
    return

    #old code
    for server in dns_list:
        if reg_exp.search(server):
            ip = query_host(hostname, server)
            ping = get_avr_ping(ip)
            print("IP:{ip}\t{time} ms".format(ip=ip, time=ping))