I am creating a code that pings a list of ips. I got it to drip and give me the answer, but I can not do the condition I want, which is:
SE ping ok:
continuar os comandos
SENÃO:
faz outra coisa.
I do not know how to manipulate the ping response to put this logic in the code, can you help me?
Sorry, I'm a beginner.
This is my code:
#coding: utf-8
import sys
import os
import platform
import subprocess
from ips_list import radius
plat = platform.system()
scriptDir = sys.path[0]
if plat == "Windows":
for ip in radius:
try:
line = ip.strip()
ping = subprocess.Popen(
["ping", "-n", "2", "-l", "1", "-w", "100", line],
stdout = subprocess.PIPE,
stderr = subprocess.PIPE
)
expect:
if plat == "Linux":
for ip in radius:
line = ip.strip( )
ping = subprocess.Popen(
["ping", "-c", "1", "-l", "1", "-s", "1", "-W", "1", line],
stdout = subprocess.PIPE,
stderr = subprocess.PIPE
)
out, error = ping.communicate()
print out
print error
How can I add this if .. else logic to it?
Thank you!