ping-check

Table of Contents

@echo off
color 0a
title ping check script
mode con:cols=80 lines=40
dir c:\ping_log || mkdir c:\ping_log
cls
echo %time% %date% 开始测试 >> ping.log

:loo
echo 正在进行ping检测,请稍候...
echo ^|^|
echo ^|^|
ping -n 2 127.1 1>nul 2>nul
echo ^|^|
ping -n 2 127.1 1>nul 2>nul
echo \/
ping -n 2 127.1 1>nul 2>nul

ping -n 2 yy.com > log.log
set /a a=0
for /f %%i in ('findstr -i ttl log.log') do set /a a=a+1
if %a% equ 0 goto :general
if %a% equ 2 echo ff 1>nul 2>nul
echo -----------------------------------------------------------------------------
echo 当前连接正常
echo -----------------------------------------------------------------------------
echo %time% %date% connection OK >> ping.log
ping -n 2 127.1 1>nul 2>nul
cls
goto :loo

:general
set /a b=0
for /f %%i in ('findstr -i general log.log') do set /a b+=1
if %b% equ 0 goto :timeout
if %b% equ 2 echo ff 1>nul
echo -----------------------------------------------------------------------------
echo 断线咯
echo -----------------------------------------------------------------------------
echo %time% %date% 断线 >> ping.log
:timeout
set /a c=0
for /f %%i in ('findstr -i out log.log') do set /a c+=1
if %c% equ 0 goto :timeout_2
if %c% equ 2 echo ff 1>nul
echo -----------------------------------------------------------------------------
echo 断线咯
echo -----------------------------------------------------------------------------
echo %time% %date% 断线 >> ping.log
:timeout_2
set /a d=0
for /f %%i in ('findstr -i 无法访问目标主机 log.log') do set /a d+=1
if %d% equ 0 goto :timeout_3
if %d% equ 2 echo ff 1>nul
echo -----------------------------------------------------------------------------
echo 断线咯
echo -----------------------------------------------------------------------------
echo %time% %date% 断线 >> ping.log
:timeout_3
set /a e=0
for /f %%i in ('findstr -i 超时 log.log') do set /a e+=1
if %e% equ 0 goto :loo
if %e% equ 2 echo ff 1>nul
echo -----------------------------------------------------------------------------
echo 断线咯
echo -----------------------------------------------------------------------------
echo %time% %date% 断线 >> ping.log

ping -n 2 127.1 1>nul 2>nul
cls
goto :loo

Posted in BAT