windows
ping -t 8.8.8.8 |cmd /q /v /c “(pause&pause)>nul & for /l %a in () do (set /p “data=” && echo(!date! !time! !data!)&ping -n 2 8.8.8.8>nul”
linux
ping 8.8.8.8 | while read line; do echo `date` - $line; done
另外遇到多網卡情況, 記錄在 https://wp.vicds.com/?p=623 , 還遇到千拖VPN有問題明明是自己網路掛掉的.
@echo off
set ip1=8.8.8.8
set ip2=192.168.1.1
set ip1name=dns
set ip2name=router
:BEGIN
PING -n 4 -w 1000 %ip1%
IF %ERRORLEVEL%==0 ECHO %DATE% %TIME% Ping %ip1name% Success >> D:\log.txt
IF %ERRORLEVEL%==1 ECHO %DATE% %TIME% Ping %pi2name% Fail >> D:\log.txt
PING -n 4 -w 1000 %ip2%
IF %ERRORLEVEL%==0 ECHO %DATE% %TIME% Ping %ip2name% Success >> D:\log.txt
IF %ERRORLEVEL%==1 ECHO %DATE% %TIME% Ping %ip2name% Fail >> D:\log.txt
GOTO BEGIN