@echo off
setlocal

:: 设置你的网卡名称
set NIC_NAME=以太网

:MENU
echo ===============================
echo 1. 设置静态 IP
echo 2. 恢复自动获取 IP (DHCP)
echo 3. 退出
echo ===============================
set /p choice=请输入选项(1/2/3):

if "%choice%"=="1" goto STATIC
if "%choice%"=="2" goto DHCP
if "%choice%"=="3" exit

:STATIC
:: 这里修改为你想要的 IP / 子网掩码 / 网关 / DNS
set IP_ADDR=192.168.31.40
set SUBNET=255.255.255.0
set GATEWAY=192.168.31.168
set DNS1=192.168.31.168


echo 设置静态 IP...
netsh interface ip set address name="%NIC_NAME%" static %IP_ADDR% %SUBNET% %GATEWAY%
netsh interface ip set dns name="%NIC_NAME%" static %DNS1%
netsh interface ip add dns name="%NIC_NAME%" %DNS2% index=2
echo 完成!
pause
goto MENU

:DHCP
echo 恢复自动获取 IP...
netsh interface ip set address name="%NIC_NAME%" source=dhcp
netsh interface ip set dns name="%NIC_NAME%" source=dhcp
echo 完成!
pause
goto MENU

记得把编码格式改为ANSI编码格式 用notepad++修改 最后改为1.bat 用管理员运行即可