通过批处理修改DNS的代码(推荐)

批处理改DNS(推荐):

代码如下:

@echo off
::判断本地连接 赋值a
for /f "tokens=3,4 delims== " %%i in ('ipconfig ^|findstr /r "本"') do echo %%i %%j >DNS.txt
for /f "tokens=1 delims==:" %%d in (DNS.txt) do set a=%%d
::请根据实际情况更改下面三行
echo 开始更改主dns
netsh interface ip set dns name="%a%" source=static addr=202.96.128.116
echo 完成
echo 开始更改副dns
netsh interface ip add dns "%a%" 202.96.128.86 index=2
del DNS.txt
exit


建议再加一个

echo 删除原始DNS
netsh interface ip del dns name="%a%" all

否则原先有DNS的就修改不了啊嘿嘿

相关推荐