用命令提示字元長時間統計線路狀況 / Ping statistics with Command Line
最近收資料的線路非常的不穩,又沒辦法24小時一直看著它,然後就變出這個東西了。每10秒鐘Ping一次,每15分會寫出檔案一次,每小時會重新統計一次。
Ping every 10 seconds. Write to file every 15 minutes. Restart every hour.
@echo off
set SVIP=123.123.123.123
set T_OUT=6000
: restartping
if not EXIST %SVIP%.斷線 (goto starting)
find /c "Request timed" %SVIP%.斷線 >> %SVIP%.連線
REM 斷線=(connection fail) 連線=(connection success)
find /c "Reply from" %SVIP%.成功 >> %SVIP%.連線
echo. >> %SVIP%.連線
echo %date:~0,10% %time% >> %SVIP%.連線
: starting
set S_DATE=%date:~0,10%
set S_TIME=%time%
if EXIST %SVIP%.斷線 (del %SVIP%.斷線)
if EXIST %SVIP%.連線 (echo ================= >> %SVIP%.連線 >> %SVIP%.連線) ELSE (echo ================= > %SVIP%.連線)
echo. >> %SVIP%.連線
echo Ping: %SVIP% Timeout: %T_OUT%ms Cycle: 10seconds >> %SVIP%.連線
echo. >> %SVIP%.連線
echo %S_DATE% %S_TIME% >> %SVIP%.連線
echo Ping: %SVIP% Timeout: %T_OUT%ms Cycle: 10seconds
echo Please Standing By...
: loopping
ping %SVIP% -n 1 -w %T_OUT% >> %SVIP%.斷線
copy %SVIP%.斷線 %SVIP%.成功
cls
echo Ping: %SVIP% Timeout: %T_OUT%ms Cycle: 10seconds
echo.
echo %S_DATE% %S_TIME:~0,8%
find /c "Request timed" %SVIP%.斷線
find /c "Reply from" %SVIP%.成功
echo.
echo %date:~0,10% %time:~0,8%
echo.
echo Type Ctrl-C to stop.
: waitping
if %time:~7,3%==0.0 (goto goping) ELSE (goto waitping)
: goping
if %time:~3,4%==15:0 (goto writing)
if %time:~3,4%==30:0 (goto writing)
if %time:~3,4%==45:0 (goto writing)
if %S_TIME:~0,2%==%time:~0,2% (goto loopping) ELSE (goto restartping)
: writing
find /c "Request timed" %SVIP%.斷線 >> %SVIP%.連線
find /c "Reply from" %SVIP%.成功 >> %SVIP%.連線
echo. >> %SVIP%.連線
echo %date:~0,10% %time% >> %SVIP%.連線
goto :loopping
More......