gpt4 book ai didi

python - 有没有快速了解另一台计算机的状态的方法?

转载 作者:太空宇宙 更新时间:2023-11-03 15:07:37 25 4
gpt4 key购买 nike

我需要知道十台计算机的状态。

尝试使用“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

谢谢!

最佳答案

尝试使用子进程

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

关于python - 有没有快速了解另一台计算机的状态的方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44510896/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com