I am trying to write my below pinging script results into the Text file, but I am getting an error message.
import os
import time
import subprocess
# Open file for saving ping results
results_file = open("results.txt", "w")
with open('ip-source.txt') as IPs:
hosts = IPs.read()
hosts = hosts.splitlines()
for ip in hosts:
os.system('cls')
print('Printing now:', ip)
print('-'*60)
result = os.system('ping -n 4 {}'.format(ip))
print('-'*60)
time.sleep(1)
with open("output.txt", "w", encoding="utf8") as output:
output.write("\n".join([post.text for post in result]))
and when i ran it i got below error message:
Traceback (most recent call last):
File "script.py", line 21, in <module>
output.write("\n".join([post.text for post in result]))