bat加时间戳ping并保存结果

@echo off
@echo.   提醒:请以管理员身份运行                                                                  
@echo.   终止请按: Ctrl+C

set /p host=host:

set logfile=%~dp0%host%.txt
echo Target Host=%host% > %logfile%

:loop
for /f "tokens=* skip=2" %%A in ('ping %host% -n 1') do (
  echo %date% %time:~0,-3% %%A>>%logfile%
  echo %date% %time:~0,-3% %%A
  timeout /t 1 /nobreak>nul
  goto loop
)
pause>nul
posted @ 2023-03-21 12:11  孙犯困  阅读(46)  评论(0编辑  收藏  举报