本文介绍了批处理-如果命令并“检查互联网连接"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过Steam和其他程序下载时,我的路由器出现问题,例如互联网失去了与路由器的连接.我无法使用电缆将PC插入路由器,因此提出了解决方案:另一个\每X秒断开连接并连接到互联网

I have problems with my router when downloading through steam and other programs, such as the internet losing connection with the router. I cant plug my pc to my router using cable so i made a solution:and the other one\Every X secounds disconect and connect to internet

但是问题是我想提高效率,所以我想要一个执行此操作的命令:

But the problem is i want to make it more efficient so i would like a command that does this:

:a\检查连接\如果已连接,则转到\如果没有连接断开并连接到互联网

:a\Check connection\if connected then goto a\if noconnection disconect and connect to internet

我在使用check connection命令时遇到问题,因为它无法继续执行if

i get problems with check connection command as its does not move on to the if

请帮助并感谢您的宝贵时间

Please help and thanks for your time

推荐答案

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

This will ping www.google.com and if there is a response then goto :a, if not connected then it will goto :Disconnected.

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

The findstr will look for the TTL (Time to live) in the ping output. Great little trick that can be applied to multiple situations.

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

You could also condense this to the below. As the script will continue if it does not findstr TTL or skip to :a if it does

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

:a
REM Your connected script here

这篇关于批处理-如果命令并“检查互联网连接"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 22:33