CMD如果ping成功,请执行此操作 [英] CMD if ping successful do this
本文介绍了CMD如果ping成功,请执行此操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
@echo关闭对于/L %% N IN(1、1、200)DO(ping -n 1 192.1.22.%% N如果不是ERRORLEVEL 1(设置pingresult = true转到完成))设置pingresult = false:完毕如果%pingresult%== true(回声皮卡丘) 别的 (回声脱机!")
它不起作用.
解决方案
感谢aschipfl我找到了答案!
您只需要使用 |在
,因为这样,如果ping成功,他将放下TTL和 ping
命令后找到"TTL ="> nul |找到"TTL => nul
将对其进行验证.这是我从网站上获得解决方案的示例.
ping -n 1 192.168.1.1 |找到"TTL => nul如果错误级别为1(回声主机无法访问) 别的 (回显主机可达)
i have situation that i can not understand, i am trying to do a batch file where he loops 200 times and in each loop he pings a host, if the ping is successful he does a command. Here is what i got:
@echo off
for /L %%N IN (1, 1, 200) DO (
ping -n 1 192.1.22.%%N
if not ERRORLEVEL 1 (
set pingresult=true
goto done
)
)
set pingresult=false
:done
if %pingresult% == true (
echo Pikachu
) else (
echo "Offline!"
)
it doesn't work.
解决方案
Thanks to aschipfl I discovered the answer!
you just have to use | find "TTL=" >nul
after the ping
command because this way if the ping was successful he devolve a TTL and the | find "TTL=" >nul
will grep it for validation. This is the example from the website I got the solution.
ping -n 1 192.168.1.1 | find "TTL=" >nul
if errorlevel 1 (
echo host not reachable
) else (
echo host reachable
)
这篇关于CMD如果ping成功,请执行此操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文