I have this code working on my CMD promt (with one % instead %%) but when I executed it through a .bat file it isn't working.
for /f "tokens=5 delims=: " %%G in ('netsh interface IPv4 show dnsserver "Ethernet 2" ^| findstr /C:"Servidores DNS configurados estáticamente"') DO (Echo %%G)
I'm trying to do a .bat that swaps my main and secondary DNS for another two. I was trying with something like this:
@echo off
cls
color A
cls
SET DNS1=46.101.36.120
SET DNS2=46.101.149.135
SET DNSGoogle1=8.8.8.8
SET DNSGoogle2=8.8.4.4
SET NAME=Ethernet 2
for /f "tokens=5 delims=: " %%G in ('netsh interface IPv4 show dnsserver "%NAME%" ^| findstr /C:"Servidores DNS configurados estáticamente"') DO IF %DNSGoogle1%==%%G (goto netflixDNS) ELSE (goto googleDNS)
:netflixDNS
echo "Netflix DNS"
netsh interface ipv4 delete dnsserver "%NAME%" all
netsh interface ip set dnsservers "%NAME%" static %DNS1%
netsh interface ip add dnsservers "%NAME%" %DNS2% index=2
ipconfig /flushdns
PAUSE
EXIT
:googleDNS
echo "Google DNS"
netsh interface ipv4 delete dnsserver "%NAME%" all
netsh interface ip set dnsservers "%NAME%" static %DNSGoogle1%
netsh interface ip add dnsservers "%NAME%" %DNSGoogle2% index=2
ipconfig /flushdns
PAUSE
EXIT
For some reason my FORisn't working...
ácharacter. I would simply shorten the text toServidores DNS configurados est.