Skip to content

Instantly share code, notes, and snippets.

@googlebe
Forked from maravedi/change_dns.bat
Created February 22, 2018 07:00
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 googlebe/922c49995d36e23d286ddd6fdc0c040a to your computer and use it in GitHub Desktop.
Save googlebe/922c49995d36e23d286ddd6fdc0c040a to your computer and use it in GitHub Desktop.
Batch Script to Change DNS Servers
@ECHO OFF
ipconfig /all | findstr "Servers" | findstr "xx.xx.xx.xx"
if %ERRORLEVEL% equ 0 (
rem echo Findstr FOUND xx.xx.xx.xx in the DNS list.
goto google
) else (
rem echo Findstr DID NOT find xx.xx.xx.xx in the DNS list.
goto local
)
:local
echo Error Level: %errorlevel% - Did not find local DNS server, inputting local settings now...
netsh interface ip delete dnsservers "Local Area Connection" all
netsh interface ip add dns name="Local Area Connection" addr=xx.xx.xx.xx index=1
netsh interface ip add dns name="Local Area Connection" addr=zz.zz.zz.zz index=2
echo Current DNS Settings:
ipconfig /all | findstr /c:"xx.xx.xx.xx"
ipconfig /all | findstr /c:"zz.zz.zz.zz"
pause
goto end
:google
echo Error Level: %errorlevel% - Found local DNS server, inputting Google settings now...
netsh interface ip delete dnsservers "Local Area Connection" all
netsh interface ip add dns name="Local Area Connection" addr=8.8.4.4 index=1
netsh interface ip add dns name="Local Area Connection" addr=8.8.8.8 index=2
echo Current DNS Settings:
ipconfig /all | findstr /c:"8.8.4.4"
ipconfig /all | findstr /c:"8.8.8.8"
pause
goto end
:end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment