0

I am trying to write a batch file to tell if the internet is down at our school. Sometimes it is a network issue, and sometimes it is a website issue. here` is the code I have so far, feel free to edit or copy and paste. I am new to batch files, and this is my first question.

@ echo off 
color B
goto pingwifi
:pingwifi
cls
ping -n 5 172.16.1.1
if errorlevel 1 (
color c
msg * WIFI DOWN
goto pingwifi
)
:pingjostens
cls
ping -n 5 192.189.112.185
if errorlevel 1 (
color c
msg * JOSTENS DOWN
goto pingwifi
)
goto pingjostens

1 Answers1

0

There are way better methods, but by just amending your script:

@echo off 
:pingwifi
color B
cls
echo Pinging Wifi
ping -n 5 127.0.0.1 >nul
if %errorlevel%==1 (
 color c
 msg * WIFI DOWN
 timeout /T 60
 goto pingwifi
) else (
goto pingjostens
)
:pingjostens
cls
echo Pinging Jostens
ping -n 5 jost >nul
if %errorlevel%==1 (
 color c
 msg * JOSTENS DOWN
 timeout /T 60
 goto pingjostens
)
goto pingwifi

It will ping Wifi, if up, it will ping Jostens, if wifi is down it will print the message and wait 60 seconds and retry ping to wifi

If wifi is up and Jostens is down, it will print message and retry after 60 seconds. If both are up it will just loop infinitely.

Gerhard
  • 22,678
  • 7
  • 27
  • 43