简体   繁体   English

从 csv 读取并检查 ip 地址可达性

[英]Read from csv and check the ip address reachability

I am reading the IP addresses from a CSV and then check if the IP addresses are reachable store the IP addresses in the list, please advise what is it that I am doing here is wrong? I am reading the IP addresses from a CSV and then check if the IP addresses are reachable store the IP addresses in the list, please advise what is it that I am doing here is wrong?

addr = []

def ip_reachable(addr):
    result = subprocess.run(f"ping -n 3 -w 1 {addr}", stdout=subprocess.DEVNULL)
    if result.returncode == 0:
        return result.returncode, addr


with open("test.csv") as file_name:
    read_csv_file = csv.DictReader(file_name)
    for index_col in read_csv_file:
        if ip_reachable(index_col["column_1"]):
            addr.append(ip_reachable)



print(addr)

Instead of:代替:

addr.append(ip_reachable)

Try this:尝试这个:

addr.append(index_col['column_1'])

I believe you want to store the address itself ie in column1 and not the method ip_reachable .我相信您想将地址本身存储在column1而不是方法ip_reachable

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM