I am not sure what is wrong with the script. The error I get is this:
filename = sys.argv[1]
IndexError: list index out of range
Code:
import subprocess, sys, re
filename = sys.argv[1]
f = open('pingfile.txt', 'r')
result = {}
def main():
print('IP, TimeToPing (ms)')
for host in f.readlines():
ping = subprocess.getoutput(f"ping -c 1 -t 2 {host}")
dns = re.findall('\d+.\d+.\d+.\d+',ping)
if 'time' in ping:
time = re.findall('time=\w+',ping)[0]
time = time.replace('time=', '')
else:
time = 'NotFound'
print(dns[0], ',', time)
if __name__ == "__main__":
main()
im not sure what im doing wrong.