Reputation: 181
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!
Upvotes: 1
Views: 190
Reputation: 16224
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()
Upvotes: 1