Skip to content

Instantly share code, notes, and snippets.

@milnak
Created May 23, 2022 15:37
Show Gist options
  • Save milnak/a26d21a1358f7882926096258b847653 to your computer and use it in GitHub Desktop.
Save milnak/a26d21a1358f7882926096258b847653 to your computer and use it in GitHub Desktop.
CMD script to verify that DNS server is up and running. Useful for pihole.
@echo off
setlocal
if "%~1"=="" ( ECHO Specify DNS server to verify, e.g. %~nx0 192.168.1.17 & GOTO :EOF)
set DNSSERVER=%~1
REM To have this script run on user login:
REM
REM taskschd.msc
REM Action, Create Basic Task
REM Name: verify_htpc_pihole
REM Start: When I log on
REM Action: Start a program
REM Program: %windir%\system32\cmd.exe
REM Arguments: /c e:\bin\verify_htpc_pihole.cmd 192.168.1.17
ECHO Verifying DNS server at %DNSSERVER% . . .
:LOOP
set OUT=
for /f "usebackq delims=" %%f in (`nslookup.exe microsoft.com %DNSSERVER% 2^>nul`) do (
SET OUT=%%f
REM Only want first line of output.
GOTO :DONE
)
:DONE
REM Should be "Server: pi.hole"
if "%OUT:~0,7%"=="Server:" (
GOTO :EOF
)
REM Assume "DNS request timed out."
echo DNS server unavailable! Retrying in 5 seconds...
REM Sleep for 5 seconds.
ping -n 6 127.0.0.1 >nul
GOTO :LOOP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment