Internet ping test + say results

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
SurRainbow
Posts: 2
Joined: 26 Nov 2019 09:05

Internet ping test + say results

#1 Post by SurRainbow » 26 Nov 2019 09:08

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

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Internet ping test + say results

#2 Post by aGerman » 26 Nov 2019 10:50

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

Yellow_13
Posts: 5
Joined: 26 Nov 2019 10:02

Re: Internet ping test + say results

#3 Post by Yellow_13 » 26 Nov 2019 23:34

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.

SurRainbow
Posts: 2
Joined: 26 Nov 2019 09:05

Re: Internet ping test + say results

#4 Post by SurRainbow » 28 Nov 2019 10:17

Can I get it to speak at all?

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Internet ping test + say results

#5 Post by aGerman » 28 Nov 2019 11:29

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

Post Reply