批处理命令和 "check internet connection"

Batch- if command and "check internet connection"

我的路由器在通过 steam 和其他程序下载时出现问题,例如互联网与路由器断开连接。我无法使用电缆将我的电脑连接到我的路由器,所以我做了一个解决方案: 和另一个 \每 X 秒断开连接并连接到互联网

但问题是我想让它更有效率,所以我想要一个执行此操作的命令:

:一个 \检查连接 \如果已连接,则转到 a \if noconnection 断开并连接到互联网

我在检查连接命令时遇到问题,因为它没有继续执行 if

请帮忙,感谢您的宝贵时间

这将 ping www.google.com,如果有响应则 goto :a,如果未连接则将 goto :Disconnected

findstr 将在 ping 输出中查找 TTL(生存时间)。可以应用于多种情况的小技巧。

ping -n 1 www.google.com | findstr TTL && goto a
ping -n 1 www.google.com | findstr TTL || goto Disconnected

:a
REM Your connected script here

:Disconnected
REM Your disconnect / reconnect script here

您也可以将其浓缩为以下内容。因为脚本将继续,如果它不 findstr TTL 或者跳到 :a 如果它

ping -n 1 www.google.com | findstr TTL && goto a
REM Your disconnect / reconnect script here

:a
REM Your connected script here

这是我做的:

@echo off 
:b
cls
:a
color 0A
ping -n 1 192.168.0.1 | findstr TTL && goto a
ping -n 1 192.168.0.1 | findstr TTL || goto Disconnected

:Disconnected
color 0C 
echo.
echo        //_No_internet_connection_\ 
echo.
echo              //_Disconnecting_\
netsh wlan disconnect
timeout /t 1
netsh wlan connect virginmedia8960851
echo.
echo             //_Connecting_\
echo.
timeout /t 6
goto b