【问题标题】:Get current system time of a machine on the network获取网络上某台机器的当前系统时间
【发布时间】:2010-10-18 15:47:56
【问题描述】:

我知道我可以这样查询我的机器的系统时间:

from datetime import datetime
datetime.now()

有没有办法在windows网络上查询另一台机器的系统时间? 例如\\mynetworkpc

【问题讨论】:

    标签: python time networking system


    【解决方案1】:

    在 Windows 机器上,net time \\<remote-ip address> 可以获取远程机器的时间,但我不知道它是否可移植。

    >>> import subprocess
    >>> subprocess.call(r"net time \\172.21.5.135")
    Current time at \\172.21.5.135 is 10/18/2010 12:32 PM
    
    The command completed successfully.
    
    0
    >>>
    

    【讨论】:

    • 这对我有用。除了ip地址,你还可以使用机器名,都可以正常工作。谢谢!
    【解决方案2】:

    您可以将 Python WMI 模块与此问题的答案结合使用:get-remote-pcs-date-time

    【讨论】:

      猜你喜欢
      • 2011-07-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-10
      • 2016-12-04
      相关资源
      最近更新 更多