Batch ERRORLEVEL ping response

前端 未结 13 1806
走了就别回头了
走了就别回头了 2020-12-14 23:05

I\'m trying to use a batch file to confirm a network connection using ping. I want to do batch run and then print if the ping was successful or not. The problem is that it a

13条回答
  •  清歌不尽
    2020-12-14 23:53

    I liked the concept of the FIND in the ping results but why not just FIND the Reply from the Address being pinged?

    In the example below I enter an IP address as a variable, PING that IP, then look for that variable in the reply string, using the FIND Command. If the Reply String contains anything other than the correct IP it reports failure.

    If you want you can just read the value of ERRORLEVEL from the FIND. That will give you a reliable value to work with.

    @echo off
    Set /P IPAdd=Enter Address:
    cls
    ping %IPAdd% | find "Reply from %IPAdd%:"
    if not errorlevel 1 set error=success
    if errorlevel 1 set error=failure
    cls
    echo Result: %error%
    pause
    

提交回复
热议问题