C:\_G\WWW\~ELISANET\INFO\tscmd153.html
<http://www.elisanet.fi/tsalmi/info/tscmd153.html>
Copyright © 2003- by Prof. Timo Salmi  
Last modified Sun 25-Nov-2018 14:56:53

 
Assorted NT/2000/XP/.. CMD.EXE Script Tricks
From the html version of the tscmd.zip 1cmdfaq.txt file
To the Description and the Index
 

This page is edited from the 1cmdfaq.txt faq-file contained in my tscmd.zip command line interface (CLI) collection. That zipped file has much additional material, including a number of detached .cmd script files. It is recommended that you also get the zipped version as a companion.

Please see "The Description and the Index page" for the conditions of usage and other such information.



153} How do I test if my Internet connection to an IP is working?

There are so many different ways of writing a code. Here is one of the many alternatives in XP
  @echo off & setlocal enableextensions
  set ok_=true
  ping -n 1 %1|find "Lost = 0">nul||set ok_=
  if defined ok_ (
    echo You have an active connection to %1
    ) else (
    echo You have NO active connection to %1
    )
  endlocal & goto :EOF

Output
  C:\_D\TEST>cmdfaq www.google.com
  You have an active connection to www.google.com

However, since ping returns an errorlevel directly, at least in XP, one can also write
  @echo off & setlocal enableextensions
  ping -n 1 194.109.6.66>nul
  if %errorlevel% EQU 0 (
    echo You have an active connection to the internet
    ) else (
    echo You have NO active connection to the internet
    )
  endlocal & goto :EOF

Alternatively, just
  @echo off & setlocal enableextensions
  (ping %1>nul && echo Success) || echo Failure
  endlocal & goto :EOF

Output
  C:\_D\TEST>cmdfaq www.google.com
  Success

[Previous] [Next]

C:\_G\WWW\~ELISANET\INFO\tscmd153.html
C:\_G\WWW\~ELISANET\FTPCMD\TSALMI.CMD /tscmd153
http://www.elisanet.fi/tsalmi/info/tscmd153.html
file:///c:/_g/www/~elisanet/info/tscmd153.html