【问题标题】:Is there a quick way to know the status of another computer?有没有快速了解另一台计算机状态的方法?
【发布时间】: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

谢谢!

【问题讨论】:

标签: python windows ping


【解决方案1】:

尝试子进程

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()

【讨论】:

  • 对不起,我忘了告诉你我是 windows。
  • @eason 你试过但没用吗?它给你什么错误?
  • [Error2] 系统找不到指定文件
  • @cricket_007 绝对正确,非常感谢,我更新了
  • @eason 我更新了答案,让我知道现在是否可行:)
猜你喜欢
  • 1970-01-01
  • 2014-12-20
  • 2011-08-07
  • 2022-11-26
  • 2019-06-25
  • 1970-01-01
  • 1970-01-01
  • 2023-02-03
  • 1970-01-01
相关资源
最近更新 更多