2022-09-26  2024-09-18    233 字  1 分钟

每隔30秒钟检查一次网络状态,如果网络异常则重启网卡,然后刷新DNS缓存。

 1@echo off
 2echo "正在监听网络状态...."
 3
 4cd C:\opt\netcheck
 5
 6:begin
 7ping akvicor.com > ping.txt
 8rem echo %errorlevel%
 9if %ERRORLEVEL% == 1 goto ping2
10goto loop
11
12:ping2
13ping baidu.com > ping.txt
14
15if %ERRORLEVEL% == 1 goto reboot
16goto loop
17
18:reboot
19echo %date% %time% "网络异常" >> errlog.log
20echo %date% %time% "正在停用网卡"
21netsh interface set interface "WLAN" disabled
22timeout /T 3 /NOBREAK
23echo %date% %time% "正在启用网卡"
24netsh interface set interface "WLAN" enable
25echo %date% %time% "网卡已重新启动...."
26echo %date% %time% "网卡已重新启动" >> errlog.log
27goto loop
28
29:loop
30ipconfig /flushdns > nul
31timeout /T 30 > nul
32goto begin

除另有声明外本博客文章均采用 知识共享 (Creative Commons) 署名 4.0 国际许可协议 进行许可转载请注明原作者与文章出处