1
我有這個代碼工作在我的CMD promt(用%代替%%),但是當我通過.bat文件執行它時,它不工作。循環工作在CMD提示符,但不是批處理文件
for /f "tokens=5 delims=: " %%G in ('netsh interface IPv4 show dnsserver "Ethernet 2" ^| findstr /C:"Servidores DNS configurados estáticamente"') DO (Echo %%G)
我想要做一個.bat,換掉我的主DNS和另一個DNS。我用這樣的嘗試:
@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
是不工作...
這是因爲'了'性格。我會簡單地將文本縮短爲「Servidores DNS configurados est」。 – wOxxOm