Batch-if 命令和“检查互联网连接" [英] Batch- if command and "check internet connection"

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

问题描述

通过 Steam 和其他程序下载时,我的路由器出现问题,例如互联网与路由器失去连接.我无法使用电缆将我的电脑插入路由器,所以我提出了一个解决方案:和另一个每隔 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检查连接如果已连接,则转到if noconnection 断开连接并连接到互联网

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

我遇到了检查连接命令的问题,因为它没有转到 if

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

请帮助并感谢您的时间

推荐答案

这将 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

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆