1

I need to know the status of ten computers.

Trying to use "PING",I get the info in ten seconds.

I want a more quick way to get this info in Windows7 64.

code:

from platform import system as system_name # Returns the system/OS name
from os import system as system_call       # Execute a shell command
def ping(host):

# Ping parameters as function of OS
parameters = "-n 1" if system_name().lower()=="windows" else "-c 1"

# Pinging
return system_call("ping " + parameters + " " + host) == 0

Thanks!

developer_hatch
  • 15,898
  • 3
  • 42
  • 75
eason
  • 171
  • 3
  • 18

1 Answers1

1

Try with subprocess

import subprocess

def ping(host):

    # Ping parameters as function of OS
    parameters = "-n" if system_name().lower()=="windows" else "-c"

    # Pinging
    return subprocess.Popen(["ping", host, parameters, '1'], stdout=subprocess.PIPE).stdout.read()
ShadowRanger
  • 143,180
  • 12
  • 188
  • 271
developer_hatch
  • 15,898
  • 3
  • 42
  • 75