Ping test - display message if fail

自古美人都是妖i 提交于 2019-12-11 05:25:39

问题


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"
)

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.

In case it is important both PC's are running windows 10

Thanks


回答1:


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
)


来源:https://stackoverflow.com/questions/47397378/ping-test-display-message-if-fail

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!