"is alive" command?

  • Thread starter Thread starter Shawn Kaluf
  • Start date Start date
S

Shawn Kaluf

Looking for some sort of "is alive" command similiar to ping, but which
would return whether or not
a machine is powered on at the moment. I can ping the machine and output
the results to a file, but
then I have to sort through that file to get the result. Looking for some
command-line app/utility which
will give me an errorlevel I can script against.

Email response is most desirable.
 
Looking for some sort of "is alive" command similiar to ping, but which
would return whether or not
a machine is powered on at the moment. I can ping the machine and output
the results to a file, but
then I have to sort through that file to get the result. Looking for some
command-line app/utility which
will give me an errorlevel I can script against.

Have you tried:
PING -n 1 128.210.137.29 && ECHO 128.210.137.29 is alive.
?
Email response is most desirable.

You post the question here, you get the answer here.
 
Shawn said:
Looking for some sort of "is alive" command similiar to ping, but which
would return whether or not
a machine is powered on at the moment. I can ping the machine and output
the results to a file, but
then I have to sort through that file to get the result. Looking for some
command-line app/utility which
will give me an errorlevel I can script against.
Hi

This should work for WinXP:

'--------------------8<----------------------
@echo off
set host=128.33.12.144
ping -n 1 %host% >nul
if %ERRORLEVEL% EQU 0 echo %host% is online
'--------------------8<----------------------



Note that the above will not work very well in all cases when
running the script from a Windows 2000 computer.

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/OS versions/languages.


So this should work fine for both WinXP and Win2k:

'--------------------8<----------------------
set host=128.33.12.144
set connected=N
for /f "Tokens=*" %%c in ('ping -n 1 %host% ^| FIND "TTL="') do (
set connected=Y
)
if "%connected%" EQU "Y" echo %host% is online
'--------------------8<----------------------
 
Thanks for the great info!

--
Ramesh, Microsoft MVP
Windows XP Shell/User
http://windowsxp.mvps.org

Torgeir Bakken (MVP) said:
Looking for some sort of "is alive" command similiar to ping, but which
would return whether or not
a machine is powered on at the moment. I can ping the machine and output
the results to a file, but
then I have to sort through that file to get the result. Looking for some
command-line app/utility which
will give me an errorlevel I can script against.
Hi

This should work for WinXP:

'--------------------8<----------------------
@echo off
set host=128.33.12.144
ping -n 1 %host% >nul
if %ERRORLEVEL% EQU 0 echo %host% is online
'--------------------8<----------------------



Note that the above will not work very well in all cases when
running the script from a Windows 2000 computer.

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/OS versions/languages.


So this should work fine for both WinXP and Win2k:

'--------------------8<----------------------
set host=128.33.12.144
set connected=N
for /f "Tokens=*" %%c in ('ping -n 1 %host% ^| FIND "TTL="') do (
set connected=Y
)
if "%connected%" EQU "Y" echo %host% is online
'--------------------8<----------------------
 
You probably won't get an email response. Two things wrong with that.
One... then others on this newsgroups won't see the answer. Two... to get
an email response you have to post from a valid email address. Spammers
will grab that and overload you with spam. Most everyone here posts from a
fictitious address.
 
Back
Top