如何让该脚本在 10 次重启后停止重启适配器?

如何让该脚本在 10 次重启后停止重启适配器?

如何让这个 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

相关内容