-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathping_test.cmd
More file actions
51 lines (42 loc) · 1.54 KB
/
ping_test.cmd
File metadata and controls
51 lines (42 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
@echo off
title 网络连通测试
@REM color 02
@REM 使用UTF-8的话,下面this_day取值就和现在不一样了,所以本文件使用GBK编码格式。
chcp 936 >nul 2>nul
@REM ========================================= 使用说明 begin =========================================
REM ADDR ---- 表示需要ping的地址,
REM DO_FAIL ---- 失败时要做的事情,比如设为一音乐文件地址,则ping失败可以打开
REM DELAY ---- ping的间隔
set ADDR=www.baidu.com
set DO_FAIL=D:\TEMP\music\bg.mp3
set DELAY=3
@REM ========================================= 使用说明 end =========================================
@REM 这三行代码使命令会在后台运行,需要时可以打开
@REM if "%1"=="hide" goto CmdBegin
@REM start mshta vbscript:createobject("wscript.shell").run("""%~0"" hide",0)(window.close)&&exit
@REM :CmdBegin
:begin
@REM 取日期放在begin后面,虽然效率低了点,但在脚本连续运行时,可支持跨天日志分包
set this_day=%date:~0,4%_%date:~5,2%_%date:~8,2%
echo ===================== 开始测试,正在ping %ADDR%...... =====================
ping %ADDR% -n 1 -l 32 >nul 2>nul
if %ERRORLEVEL% EQU 0 (
goto good
)^
else (
goto error
)
:error
echo 唔----%ADDR% 不能访问! %DELAY%秒后进行下一次尝试
echo %time% ping %ADDR% failed,ERRORLEVEL=%ERRORLEVEL% >> "ping_test_%this_day%.log"
@REM %DO_FAIL%
goto finish
:good
echo 耶! %ADDR% 可以访问! %DELAY%秒后进行下一次尝试.
echo %time% ping %ADDR% successful >> "ping_test_%this_day%.log"
goto finish
:finish
if %DELAY% NEQ 0 (
timeout /nobreak /t %DELAY%
)
goto begin