Hi,
In this post, I'm going to introduce you how to ping network device using Python script.
import subprocess
online = []
offline=[]
with open("ip_list.txt","r") as file:
ip_adresses=file.read().split("\n")
for ip in ip_adresses:
send_ping = subprocess.call('ping %s -n 4 '% ip)
if(send_ping) == 0:
online.append(ip)
else:
offline.append(ip)
with open("reach.txt","w") as file:
for x in online:
file.write(x +"\n")
with open("not_reach.txt","w") as file:
for y in offline:
file.write(y +"\n")That's all.
If you have any questions, please comment below.