Twitist Forums
how to check internet connection through a batch file and trigger a acrion if connection is found? - Printable Version

+- Twitist Forums (http://twitist.com)
+-- Forum: Other forums (/forum-31.html)
+--- Forum: General Internet related Qustions (/forum-32.html)
+--- Thread: how to check internet connection through a batch file and trigger a acrion if connection is found? (/thread-157679.html)



how to check internet connection through a batch file and trigger a acrion if connection is found? - 129 - 05-19-2014 10:36 PM

how to check internet connection through commands of command prompt whenever computer is started ?
if internet connection is available then i want trigger a action i.e. i want run another command
if internet connection is not available then again check of connection should be made after few minutes
i want all this to happen in BACKGROUND through a batch file


- Bob - 05-19-2014 10:43 PM

ping internic.net, if you get a reply then you are on the internet


- husoski - 05-19-2014 10:52 PM

Batch won't really run "in the background". It always has a console window. You can set up a shortcut to your batch file that starts minimized, but it will show up on your task bar.

But, like the other answer said, ping a known domain name with something like:

ping -n 2 google.com >nul
if errorlevel 1 goto NO_INTERNET

That will fail, though, if your ISP or some firewall or gateway along the way discards ICMP packets. Where I work, no pings or tracerts make it out of the local network.