Ping测试-如果失败则显示消息 [英] Ping test - display message if fail
问题描述
我希望每天在登录时运行一个脚本,以测试本地网络上的PC是否在线.仅当PC处于离线状态时,才会显示一条消息.
I wish to run a script at logon each day to test if a PC on the local network is online or not. A message should only be displayed if the PC is offline.
出于测试目的,我使用的批处理文件是最接近的-
For test purposes using a batch file the closest I have got is this -
@echo off
ping -n 1 192.168.0.6 >nul &&(
START CMD /C "ECHO online && PAUSE"
)||(
START CMD /C "ECHO offline && PAUSE"
)
这将打开一个相对于在线"消息的窗口,但是如果我将IP地址更改为错误的IP地址,我仍然会看到相同的消息框.
which opens a window relative to the 'online' message but if I change the IP address to an incorrect one I still get the same message box.
如果重要的是两台PC都运行Windows 10
In case it is important both PC's are running windows 10
谢谢
推荐答案
您可能会得到Reply from <localhost>: destination unreachable
,即成功".更好地搜索TTL=
:
you probably get Reply from <localhost>: destination unreachable
, which is "success". Better search for TTL=
:
ping -n 1 <address> |find "TTL=" && (
echo Online
) || (
echo Offline
)
这篇关于Ping测试-如果失败则显示消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!