贴上昨天回答别人的代码,请按实际情况自行修改~
@echo off
color 3f
mode con cols=40 lines=15
title 自订IP切换脚本 By 暗夜
:start
cls
echo=
echo =======================================
echo=
echo 1.切换到办公室IP
echo=
echo 2.切换到家里的IP
echo=
echo 3.切换到自动获取
echo=
echo 0.退·出·脚·本
echo=
echo =======================================
echo=
set choice=
set /p choice=请输入你的选择:
if "%choice%"=="1" goto office
if "%choice%"=="2" goto Home
if "%choice%"=="3" goto DHCP
if "%choice%"=="0" exit
:office
cls
cls
echo.
echo 正在设置IP为办公IP请等待...
echo.
set net_interface="本地连接"
echo 设置IP中...
netsh interface ip set address "%net_interface%" source=static addr=192.168.1.111 mask=255.255.255.0
echo 设置IP成功...设置网关中...
netsh interface ip set address name="%net_interface%" gateway=192.168.1.1 gwmetric=1
echo 设置网关成功...设置DNS中...
netsh interface ip set dns "%net_interface%" static 218.85.152.99
netsh interface ip add dns "%net_interface%" 218.85.157.99 index=2
echo IP已成功切换到办公设置,任意键返回...
pause>nul
goto start
:home
cls
echo.
echo 正在设置为家用IP请等待...
echo.
set net_interface="本地连接"
echo 设置IP中...
netsh interface ip set address "%net_interface%" source=static addr=192.168.1.111 mask=255.255.255.0
echo 设置IP成功...设置网关中...
netsh interface ip set address name="%net_interface%" gateway=192.168.1.1 gwmetric=1
echo 设置网关成功...设置DNS中...
netsh interface ip set dns "%net_interface%" static 218.85.152.99
netsh interface ip add dns "%net_interface%" 218.85.157.99 index=2
echo IP已成功切换到办公设置,任意键返回...
pause>nul
goto start
:DHCP
echo.
echo 正在设置IP为自动获取,请等待...
echo.
echo 设置IP中...
netsh interface ip set address name="%net_interface%" source=dhcp
echo 设置网关成功...设置DNS中...
netsh interface ip set dns "%net_interface%" source=dhcp
echo 设置成功!按任意键返回选择菜单。
pause>nul
GOTO start