我来自美国国外,我非常喜欢Netflix。这就是我坚持一键更改DNS的原因。我写了一些代码,但它不起作用,我不知道,为什么它没有。这是:
`Echo On
IF netsh interface ipv4 set dnsserver "Wi-Fi" source=dhcp==netsh interface ipv4 set dnsserver "Wi-Fi" source=dhcp DO (
netsh interface ipv4 add dnsserver "Wi-Fi" 123.123.123.123
netsh interface ipv4 add dnsserver "Wi-Fi" 123.123.123.124 index=2
ECHO DNS has changed to specific.
)
ELSE (
netsh interface ipv4 set dnsserver "Wi-Fi" source=dhcp
ECHO DNS has changed to automatic.
)
ipconfig /flushdns
`
即使无法检查错误,因为cmd会自动退出。 每个命令都有效,所以我搞砸了"如果"? 帮助将不胜感激< 3
答案 0 :(得分:0)
IF "netsh interface ipv4 set dnsserver "Wi-Fi" source=dhcp" == "netsh interface ipv4 set dnsserver "Wi-Fi" source=dhcp" (
a)如果可能有空格,请将您的字符串括在qoutes中。
b)DO
if
c))
和ELSE
以及(
必须位于同一物理线路上:
) else (
答案 1 :(得分:0)
我很喜欢我的问题,多亏了你,我得到了解决方案。我使用文件比较命令以我想象的方式执行此操作。这是:
@echo off
REM At first, define an interface you're using by command "netsh interface ipv4 show dnsserver".
REM Depends on language the names could be diffrent.
REM Example: Wireless Network Connection / Local Area Connection / Wi-Fi
set INTERFACE=Wi-Fi
set DNS1=123.123.123.123
set DNS2=123.123.123.124
REM Here we goes:
netsh interface ipv4 show dnsserver "%INTERFACE%" > C:\DNS.txt
fc /b DNS.txt DNX.txt > nul
IF errorlevel 1 (
netsh interface ipv4 set dnsserver "%INTERFACE%" source=dhcp
ECHO DNS has changed to automatic.
ECHO.
) else (
netsh interface ipv4 add dnsserver "%INTERFACE%" %DNS1%
netsh interface ipv4 add dnsserver "%INTERFACE%" %DNS2% index=2
ECHO DNS has changed to static.
ECHO.
)
ipconfig /flushdns > nul
netsh interface ipv4 show dnsserver "%INTERFACE%" > DNX.txt
pause
似乎工作了:)再次感谢您的帮助:)