【发布时间】:2017-11-14 14:32:57
【问题描述】:
我需要知道十台电脑的状态。
尝试使用“PING”,十秒后我得到信息。
我想要在 Windows7 64 中更快速地获取此信息。
代码:
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
谢谢!
【问题讨论】:
-
如果机器不允许ping怎么办?
-
顺便说一句:将
system别名为system_call会使阅读您的代码的人感到困惑——system运行一个shell 命令;它不执行系统调用。 -
“状态”是什么意思?