Batch ERRORLEVEL ping response

前端 未结 13 1515
走了就别回头了
走了就别回头了 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:49

    Based on Alex K's note, this works for me on Windows 7:

    @echo off
    setlocal enableextensions enabledelayedexpansion
    
    for /f %%i in (PCS.TXT) do (
       SET bHOSTUP=0
       ping -n 2 %%i |find "TTL=" > NUL && SET bHOSTUP=1
       IF !bHOSTUP! equ 1 (
          CALL :HOSTUP %%i
       ) else (
          CALL :HOSTDOWN %%i 
       )
    )
    GOTO EOF
    
    :HOSTUP
    echo Host UP %1
    GOTO EOF
    
    :HOSTDOWN
    echo Host DOWN %1
    GOTO EOF
    
    :EOF
    exit /B
    

提交回复
热议问题