windows環境 ,
將以下代碼保存為 .bat文件
@echo off
@echo.----------------------------------------------------------
@echo.-----------------------------------------------------------
@echo off
set /p host=please input your destination ip :
set logfile=Log_%host%.log
echo Target Host = %host% >%logfile%
for /f "tokens=*" %%A in ('ping %host% -n 1 ') do (echo %%A>>%logfile% && GOTO Ping)
:Ping
for /f "tokens=* skip=2" %%A in ('ping %host% -n 1 ') do (echo %date% %time:~0,2%:%time:~3,2%:%time:~6,2% %%A>>%logfile%echo %date% %time:~0,2%:%time:~3,2%:%time:~6,2% %%Atimeout 1 >NUL GOTO Ping)
雙擊后,即開始執行長ping,會將輸出寫入到當前目錄下的log_IP文件中。
如下圖