Skip to content

Instantly share code, notes, and snippets.

@maravedi
Created April 20, 2017 15:34
Show Gist options
  • Save maravedi/54879c327205c0f56a97b415b7cca34d to your computer and use it in GitHub Desktop.
Save maravedi/54879c327205c0f56a97b415b7cca34d 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