net connectivity

  • Thread starter Thread starter pacho baratta
  • Start date Start date
P

pacho baratta

i need a batch to check for network connectivity.
i want to ping a server and if server fails do something as
send mail or other.
any hint appreciated
 
sorry, i did not explain myself.
what i nedd is a script that ping a server and if ping
fails then it exec a command, or an external script.
i wrote something like this:

ping xxx.xxx.xxx.xxx > c:\bin\ping.log
FINDSTR /I "Request failed" c:\bin\ping.log >NUL
IF %ERRORLEVEL%==1 netsh.cmd&&mail.vbs

but does not work. %ERRORLEVEL% comes always 0.

hints?
tnx, pacho


netsh.cmd is another script i set that change the ip of my
machine and send me a mail (mail.vbs) to notify me of what
happened.
now my problem is that
 
pacho said:
sorry, i did not explain myself.
what i nedd is a script that ping a server and if ping
fails then it exec a command, or an external script.
i wrote something like this:

ping xxx.xxx.xxx.xxx > c:\bin\ping.log
FINDSTR /I "Request failed" c:\bin\ping.log >NUL
IF %ERRORLEVEL%==1 netsh.cmd&&mail.vbs

but does not work. %ERRORLEVEL% comes always 0.

Hi

It is better to test for "TTL=" in the output from ping (indicating a
successful connection). Take a look at this thread for more:

http://groups.google.com/[email protected]
 
It is better to test for "TTL=" in the output from ping (indicating a
successful connection).

Why not just checking the errorlevel after the ping-command?
 
Per K. Nielsen said:
Why not just checking the errorlevel after the ping-command?

Hi

Sadly, on Win2k, ping.exe will return errorlevel 0 even if
computer is unavailable (offline/turned off) but defined in
DNS (ping will return "Request timed out.")

From my testing, the only time the function will return a correct
"False" value is where ping returns "Unknown host".

Parsing the output from ping.exe and looking for "TTL=" is the way
I have found that will work in all situations/languages.

For a VBScript version, take a look at the function IsConnectible in
the link below, it will work on all OS versions (it uses ping.exe to
ping the host and looks for the text "TTL=" to see if it is online):

http://groups.google.com/[email protected]
 
Back
Top