![如何让该脚本在 10 次重启后停止重启适配器?](https://linux22.com/image/1594190/%E5%A6%82%E4%BD%95%E8%AE%A9%E8%AF%A5%E8%84%9A%E6%9C%AC%E5%9C%A8%2010%20%E6%AC%A1%E9%87%8D%E5%90%AF%E5%90%8E%E5%81%9C%E6%AD%A2%E9%87%8D%E5%90%AF%E9%80%82%E9%85%8D%E5%99%A8%EF%BC%9F.png)
如何让这个 Windows 批处理脚本在 10 次重启后停止重启适配器?
@echo off
:loop
timeout /t 8
echo Checking...
ping -n 1 192.168.1.1|Findstr /I /C:"timed" /C:"unreachable" /C:"find host" /C:"failure"
if %errorlevel%==0 (echo Restarting...
netsh interface set interface name="Local Area Connection" admin="disabled"
netsh interface set interface name="Local Area Connection" admin="enabled")
goto loop
答案1
知道了。
@echo off
set /a restarts=1
:loop
timeout /t 6
echo Checking...
ping -n 1 192.168.1.1 | findstr /i /c:"timed" /c:"unreachable" /c:"find host" /c:"failure"
if %errorlevel%==0 (echo Restart attempt #%restarts%...
netsh interface set interface name="Local Area Connection" admin="disabled"
netsh interface set interface name="Local Area Connection" admin="enabled"
set /a restarts+=1)
if %restarts%==6 exit
goto loop