Created
July 21, 2023 17:14
-
-
Save imbyc/2a61b369e72e8bee01843d2399cdf89e to your computer and use it in GitHub Desktop.
[切换dns脚本] #bat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off & setlocal enabledelayedexpansion | |
REM 获取网卡名称 | |
: | |
@echo off & setlocal enabledelayedexpansion | |
echo. & echo 正在抓取网卡名称…… | |
set m=0 | |
for /f "tokens=1* delims=," %%a in ('Getmac /v /nh /fo csv') do ( | |
set /a m+=1 | |
set "name!m!=%%a" | |
set "name=%name:~1,-1%" | |
) | |
:Select_Card | |
echo. & echo 1:!name1! & echo 2:!name2! & echo 3:!name3! & echo 4:!name4! & echo 5:!name5! & echo. | |
set /p "Select_Card=选择网卡[最多五张]:" | |
if "%Select_Card%" == "1" ( set "card=!name1!" ) else ( | |
if "%Select_Card%" == "2" ( set "card=!name2!" ) else ( | |
if "%Select_Card%" == "3" ( set "card=!name3!" ) else ( | |
if "%Select_Card%" == "4" ( set "card=!name4!" ) else ( | |
if "%Select_Card%" == "5" ( set "card=!name5!" ) else ( echo. & echo 未键入任何参数! & pause>nul & cls & goto :Select_Card ))))) | |
rem echo. & echo 选择网卡:%card% | |
SET card=%card:"=% | |
rem 强制获取管理员权限 | |
rem %1 mshta vbscript:CreateObject("Shell.Application").ShellExecute("cmd.exe","/c %~s0 ::","","runas",1)(window.close)&&exit | |
rem //设置变量 | |
echo. & echo 选择网卡: %card% | |
set name=%card% | |
REM ################### START ################### | |
:DNS_CONFIG | |
echo. | |
set /p dnsconfig=指定DNS, 1:谷歌, 2:阿里, 3:114, 4:自动 : | |
if /i %dnsconfig%==1 goto :DNS_GOOGLE | |
if /i %dnsconfig%==2 goto :DNS_ALI | |
if /i %dnsconfig%==3 goto :DNS_114 | |
if /i %dnsconfig%==4 goto :DNS_AUTO | |
REM 设定谷歌DNS | |
:DNS_GOOGLE | |
set dns1=8.8.4.4 | |
set dns2=8.8.8.8 | |
goto :DNS_SET | |
REM 设定阿里DNS | |
:DNS_ALI | |
set dns1=223.5.5.5 | |
set dns2=119.29.29.29 | |
goto :DNS_SET | |
REM 设定114DNS | |
:DNS_114 | |
set dns1=114.114.115.115 | |
set dns2=114.114.114.114 | |
goto :DNS_SET | |
REM 设定自动获取DNS | |
:DNS_AUTO | |
netsh interface ip set dns name=%name% source=dhcp register=PRIMARY | |
netsh interface ip set wins name=%name% source=dhcp | |
REM DNS设置生效 | |
:DNS_SET | |
netsh -c interface ip set dns name="%name%" static %dns1% >nul | |
netsh -c interface ip add dns name="%name%" addr=%dns2% index=2 >nul | |
echo. 首选DNS = %dns1% .完成设置 | |
echo. 备用DNS = %dns2% .完成设置 | |
goto :SETEND | |
REM 结束 | |
:SETEND | |
echo. | |
echo. | |
echo. | |
pause |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment