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
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.