1
I’m creating a code that pings a list of ips. I managed to make him drip and give me the answer, but I can’t make the condition that I want, which is:
SE ping ok:
   continuar os comandos
SENÃO:
   faz outra coisa.
I don’t know how to manipulate the ping response to put this logic in the code, can 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 logic.. I lse in it?
Thank you!