Home:ALL Converter>Troubleshooting Script to ping multiple remote servers with python

Troubleshooting Script to ping multiple remote servers with python

Ask Time:2018-04-12T22:08:01         Author:Alec M

Json Formatter

I wrote a brief python script to read through a text file containing multiple remote server IP addresses, I'm wanting to ping each address then print which IPs are not reachable and which are.

import subprocess
`import os
response = subprocess.call(['ping', '-c', '3'])
file = open('IPlist.txt', "r")
def check_IP_from_file(filename):
for lines in file:
ping_reply = subprocess.call(['ping', '-c', '3'])
if response == 0:
print lines, ping_reply
else: 
  print lines, "is down!

My output looks like:

Usage: ping [-aAbBdDfhLnOqrRUvV] [-c count] [-i interval] [-I interface]
[-m mark] [-M pmtudisc_option] [-l preload] [-p pattern] [-Q tos]
[-s packetsize] [-S sndbuf] [-t ttl] [-T timestamp_option]
[-w deadline] [-W timeout] [hop1 ...]
destination
10.208.132.184 is down

It seems to only check the last IP on the List and Spits out a bunch of options for Ping's usage. in my script I do have Ping options defined. this is where I am very confused. I'm fairly new to python, so I'm okay with being called a noob, just please point me in the right direction.

Author:Alec M,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/49798741/troubleshooting-script-to-ping-multiple-remote-servers-with-python
yy