R
R
Rad1us2015-12-09 11:18:02
Computer networks
Rad1us, 2015-12-09 11:18:02

We write Ping to a file. Which Errorlevel to choose?

I wrote the following script in a .bat file:

@Echo Off
 
:begin
 
echo Date %date:~0,2%-%date:~3,2%-%date:~6,4% Time%time%>> %DATE%.txt
 
ping -n 5 192.168.1.100>> %DATE%.txt
if errorlevel 1 echo ALARM Date %date:~0,2%-%date:~3,2%-%date:~6,4% Time%time% >>"%date%ALARM_192.168.1.100.txt"
ping -n 30 127.0.0.1 >nul
 
echo ********************************************************>> %DATE%.txt
 
goto begin

Everything works, but in the process I found the following:
errorlevel 1 is "the timeout for the request has been exceeded"
errorlevel 0 is "the specified host is unavailable" and "packet exchange ... (normal ping)"
Question: I need to write to the alarm file and when it is exceeded interval and when the specified host is unavailable. How to do this if the "host is down" errorlevel is like a normal ping?
And one more thing: what is the fundamental difference between "the given node is unavailable" and "the timeout for the request has been exceeded"

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
res2001, 2015-12-17
@rad1us

I did this:
2>nul ping %IP% | 1>nul 2>&1 findstr "TTL" || (echo.Error
) in the ping output, we are looking for an occurrence of the TTL substring, if not found, then an error.
This works more reliably than checking errorlevel pinga.

A
Andrey Burov, 2015-12-09
@BuriK666

The host is unreachable, this is ICMP Type 3
A The timeout for the request has been exceeded - this is no response at all ..

V
Vasily, 2015-12-17
@CTpaHHoe

Do you need an alarm when the host is unavailable?
Then something like this (my script waits for the host to be available)
: connect
ping -n 2 %VPN_HOST% | find /i "TTL="
if %ERRORLEVEL%==1 (
echo "%VPN_HOST%" not reachable
call :sleep 10
goto connect
)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question