none
ALIVE OR DEAD RRS feed

  • Question

  • This scrip does everything i need it to, but the alive or dead is not specific enough.

    @echo off
    set fnm=c:\test\ipaddresses.txt
    set lnm=c:\scripts\results.txt

    if exist %fnm% goto Label1

    echo.
    echo Cannot find %fnm%
    echo.
    Pause
    goto :eof

    :Label1
    echo PingTest STARTED on %date% at %time% > %lnm%
    echo ================================================= >> %lnm%
    echo.
    for /f %%i in (%fnm%) do call :Sub %%i
    echo.
    echo ================================================= >> %lnm%
    echo PingTest ENDED on %date% at %time% >> %lnm%
    echo ... now exiting
    goto :eof

    :Sub
    echo Testing %1
    set state=alive
    ping -n 1 %1
    if errorlevel 1 set state=dead
    echo %1 is %state% >> %lnm%

    How it is set now if the reply from the ping is "reply from (ipaddress): destination host unreachable.". It puts this as alive when it needs to be dead. How can i fix this? I have self taught most of the scripting I know so if this is a stupid question I'm sorry. Any help is greatly appreciated.
    Tuesday, August 25, 2015 6:14 PM

Answers

  • I actually asked my coworker about it and he didn't know. Then 10 min later he was like OMG use this. Just completely out of nowhere. It was pretty funny. This is what i am using now.

    ping -n 1 %1 | find "Reply from %1" || set state=dead
    echo %1 is %state% >> %lnm%

    Thanks a lot again for the speedy replies guys.

    • Marked as answer by Ghost762 Tuesday, August 25, 2015 7:23 PM
    Tuesday, August 25, 2015 7:22 PM

All replies

  • Don't waste your time learning batch files.  They are obsolete:

    $outfile='c:\scripts\results.txt'
    $ips=Get-Content c:\test\ipaddresses.txt
    "PingTest STARTED on $($datetime]::Now)" | Out-File $outfile
    foreach($ip in $ips){
        if(Test-Conenction $ip -count 1 -quiet){
            "$ip is ALIVE" | Out-File $outfile -append
        }else{
            "$ip is DEAD" | Out-File $outfile -append
        }
    }
    "PingTest ENDED on  $($datetime]::Now)" | Out-File $outfile -append
    
    


    \_(ツ)_/

    Tuesday, August 25, 2015 6:54 PM
  • ping -n 1 %1

    if errorlevel 1 set state=dead

    Your test is flawed. To make it reliable you must use this code:

    ping  %1 | find /i "bytes=" || set state=dead

    • Marked as answer by Ghost762 Tuesday, August 25, 2015 7:17 PM
    • Unmarked as answer by Ghost762 Tuesday, August 25, 2015 7:23 PM
    Tuesday, August 25, 2015 6:59 PM
  • Thanks much and I'm starting to see why. Have a good one. Thanks for the speedy reply to all.
    Tuesday, August 25, 2015 7:15 PM
  • I actually asked my coworker about it and he didn't know. Then 10 min later he was like OMG use this. Just completely out of nowhere. It was pretty funny. This is what i am using now.

    ping -n 1 %1 | find "Reply from %1" || set state=dead
    echo %1 is %state% >> %lnm%

    Thanks a lot again for the speedy replies guys.

    • Marked as answer by Ghost762 Tuesday, August 25, 2015 7:23 PM
    Tuesday, August 25, 2015 7:22 PM