Page 1 of 1

Internet ping test + say results

Posted: 26 Nov 2019 09:08
by SurRainbow
I'm wondering if I could make a batch file that checks internet connection
If connection is successful then say Internet connected
If connection unsuccessful then say Internet disconnected

Thanks
-SR

Re: Internet ping test + say results

Posted: 26 Nov 2019 10:50
by aGerman
Easiest way is to ping a common web site, such as google.com

Code: Select all

@echo off &setlocal
>nul ping google.com -n 1
if errorlevel 1 (echo Internet disconnected) else echo Internet connected
pause
That doesn't protect you from getting a false result if google is down though. Unlikely but still possible.

Steffen

Re: Internet ping test + say results

Posted: 26 Nov 2019 23:34
by Yellow_13
Could it be possible to add this script 3 times with 3 different sites as to mak sure that the ping results are correct? Sometimes, there might be issues with one site that messes up your ping data, but basing the results on different sites (preferably non affiliated with Google, if you use google.com as your first "target") would eliminate that risk.

Re: Internet ping test + say results

Posted: 28 Nov 2019 10:17
by SurRainbow
Can I get it to speak at all?

Re: Internet ping test + say results

Posted: 28 Nov 2019 11:29
by aGerman
Yellow_13 wrote:
26 Nov 2019 23:34
Could it be possible to add this script 3 times with 3 different sites
Sure. Just ping 3 sites and if you get errorlevel 0 for one of them you may assume that you're connected. Perhaps you want to contribute the code for that?
SurRainbow wrote:
28 Nov 2019 10:17
Can I get it to speak at all?
Oh, you literally talked about speaking. Well, not using Batch allone. A JScript hybrid should work though.
*.bat

Code: Select all

@if (0)==(0) echo off &setlocal

>nul ping google.com -n 1
if errorlevel 1 (set "msg=Internet disconnected") else set "msg=Internet connected"
cscript //nologo //e:jscript "%~fs0" "%msg%"

goto :eof @end
WScript.CreateObject('SAPI.SpVoice').Speak(WScript.Arguments(0));
Steffen