【问题标题】:Windows Batch File Ping an IP and display round trip timeWindows 批处理文件 Ping IP 并显示往返时间
【发布时间】:2013-11-06 17:13:33
【问题描述】:

我用 C# 写了这个,但我需要将它写在一个批处理文件中。如何在无限循环中每 5 秒 ping 一个 IP 地址并显示 (echo) 往返时间?

我知道在 C# 中有

System.Threading.Thread.Sleep(5000); 

使用continue,您可以返回到循环的顶部,但不知道如何在批处理文件中执行此操作。

【问题讨论】:

    标签: batch-file ping latency


    【解决方案1】:
    :start
    sleep 5
    rem Do something...
    goto :start
    

    【讨论】:

      【解决方案2】:
      :LoopBack
      
      FOR /F "delims=@" %%a IN ( 'ping 127.0.0.1' ) DO ( SET TRIP_TIME=%%a )
      ECHO %TRIP_TIME%
      
      REM Prompts you to enter a choice with a timeout of five seconds.
      CHOICE /C YN /D N /N /T 5
      
      call :LoopBack
      

      假设 ping 输出的最后一行是您要查找的往返时间。

      【讨论】:

        【解决方案3】:
        @echo off
            for /L %%f in (1 0 2) do (
                ping 127.0.0.1 | call findstr "Average"
                if errorlevel 1 echo %date% %time% : Not Found
                choice /t 5 /c y /d y /n /m "" >nul
            )
        

        【讨论】:

          猜你喜欢
          • 2022-01-23
          • 2012-02-28
          • 1970-01-01
          • 1970-01-01
          • 2013-01-24
          • 1970-01-01
          • 1970-01-01
          • 2022-10-21
          • 2011-12-01
          相关资源
          最近更新 更多