[英]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?
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)
代替:
addr.append(ip_reachable)
尝试这个:
addr.append(index_col['column_1'])
我相信您想将地址本身存储在column1
而不是方法ip_reachable
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.