[英]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.