Skip to content

Instantly share code, notes, and snippets.

@Ultrabenosaurus
Last active June 29, 2022 21:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ultrabenosaurus/c2cd3066c4492a2dafdce5b722a6d701 to your computer and use it in GitHub Desktop.
Save Ultrabenosaurus/c2cd3066c4492a2dafdce5b722a6d701 to your computer and use it in GitHub Desktop.
A quick and dirty Windows CMD batch script to quickly and easily swap between pre-configured DNS addresses on the main WiFi adaptor, designed for laptop users who have a Raspberry Pi or similar device as a DNS filter on their home network which can't be reached when away from home. Must be run with admin priviledges.
@echo off
:: ==========
:: Code to automatically request UAC elevation via PowerShell if launched without admin priviledges.
::
:: source: https://stackoverflow.com/a/24665214
:: license: https://creativecommons.org/licenses/by-sa/4.0/
:: changes: none
:: ==========
:: Check privileges
net file 1>NUL 2>NUL
if not '%errorlevel%' == '0' (
powershell Start-Process -FilePath "%0" -ArgumentList "%cd%" -verb runas >NUL 2>&1
exit /b
)
:: Change directory with passed argument. Processes started with
:: "runas" start with forced C:\Windows\System32 workdir
cd /d %1
:: ==========
:: A quick and dirty Windows CMD batch script to quickly and easily swap between pre-configured DNS addresses
:: on the main WiFi adaptor, designed for laptop users who have a Raspberry Pi or similar device as a DNS
:: filter on their home network which can't be reached when away from home. Must be run with admin priviledges.
::
:: source: https://gist.github.com/Ultrabenosaurus/c2cd3066c4492a2dafdce5b722a6d701
:: license: https://creativecommons.org/licenses/by-sa/4.0/
:: ==========
SETLOCAL
:: IP address of your internal filtering device
set it_dns=192.168.1.254
:: AdGuard public DNS https://adguard-dns.io/en/public-dns.html
set ag_dns=94.140.14.14
:: Google public DNS https://developers.google.com/speed/public-dns
set gg_dns=8.8.8.8
:: Cloudflare public DNS https://1.1.1.1/
set cf_dns=1.1.1.1
:: Quad9 public DNS https://www.quad9.net/
set qd_dns=9.9.9.9
echo Which DNS would you like to use for WiFi connection?
echo a) Internal Filter
echo b) AdGuard
echo c) Google
echo d) Cloudflare
echo e) Quad9
echo z) Custom
set /p dns=""
if %dns%==a goto intl
if %dns%==b goto adgd
if %dns%==c goto goog
if %dns%==d goto cdfr
if %dns%==e goto quad
if %dns%==z goto cstm
echo Invalid entry: %dns%
pause
goto end
:intl
echo Setting DNS to %it_dns%
netsh interface ip set dns "WiFi" static %it_dns%
pause
goto end
:adgd
echo Setting DNS to %ag_dns%
netsh interface ip set dns "WiFi" static %ag_dns%
pause
goto end
:goog
echo Setting DNS to %go_dns%
netsh interface ip set dns "WiFi" static %go_dns%
pause
goto end
:cdfr
echo Setting DNS to %cf_dns%
netsh interface ip set dns "WiFi" static %cf_dns%
pause
goto end
:quad
echo Setting DNS to %qd_dns%
netsh interface ip set dns "WiFi" static %qd_dns%
pause
goto end
:cstm
set /p ip="Enter IP: "
echo Setting DNS to %ip%
netsh interface ip set dns "WiFi" static %ip%
pause
goto end
:end
ENDLOCAL
@echo on
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment