I'm working on script that checks on ping from several groups of devices and writing the devices ip to text file when the ping is successful
import os
ip_list=[]
data = open("data.txt",'w')
def pngtest():
g=4
s=2
e=106
while g < 11:
for ip in range(s,e):
ip_list.append('10.0.'+str(g)+'.'+str(ip))
if g == 8:
s=5
e=122
elif g == 9:
s=2
e=198
elif g == 10:
s=2
e=254
else:
s=2
e=106
g +=1
pngtest()
for ip in ip_list:
response = os.popen(f"ping {ip}").read()
if "Received = 4" in response and 'TTL' in response:
data.write(f"{ip}")
else:
print(f"ping {ip} failed")
data.close()
the problem is that it seems that the script does not writing any data to the text file. how do I fix this?