【问题标题】:ping constantly an IP and write into txt不断ping一个IP并写入txt
【发布时间】:2023-01-03 15:12:47
【问题描述】:

我有这个代码

def ping_google(command):
    with open('google.txt', 'a') as f:
        f.write(subprocess.check_output(command))

t1 = threading.Thread(target=ping_anel, args=("ping -t 8.8.8.8",))

我想将对 google 的无限 ping 保存在一个 txt 文件中。可能吗?

【问题讨论】:

    标签: python cmd ping


    【解决方案1】:
    command = "ping -i20 8.8.8.8  > ping.txt"
    

    要求subprocess, shell=True一起执行, 你就完成了。 它将永远每分钟附加三个状态报告, 或者直到您按下 CTRL/C。

    (我期待ping-t 切换后需要一个生存时间值, 所以我不确定你的命令的意图是什么。)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-31
      • 2021-02-06
      • 1970-01-01
      相关资源
      最近更新 更多