目录

问题

公司是固定IP模式,每次来回切换太麻烦了,现在一个脚本自动搞定,太爽啦

解决

环境:Windows 10

@echo off
color 00
mode con cols=80 lines=30
title IP模式切换脚本
:start
cls
echo=
echo ============================================================================
echo=
echo                             1.办公模式
echo=
echo                             2.居家模式
echo=
echo                             3.无所谓模式(DHCP)
echo=
echo                             4.退出
echo=
echo ============================================================================
echo=
set choice=
set /p choice=请输入你的选择:
if "%choice%"=="1" goto work
if "%choice%"=="2" goto home
if "%choice%"=="3" goto dhcp
if "%choice%"=="4" exit
echo 输入有误,请重新选择!
pause>nul
goto start
 
:work
cls
cls
echo.
echo 正在切换至办公模式请等待...
echo.
set net_interface="WLAN"
echo 设置IP、网关中...
netsh interface ip set address "%net_interface%" static 192.168.1.166 255.255.255.0 192.168.1.1
echo 设置DNS中...
netsh interface ip set dns "%net_interface%" static 223.5.5.5
echo IP已成功切换至办公模式,任意键返回...
pause>nul
goto start
 
:home
cls
echo.
echo 正在切换至居家模式请等待...
echo.
set net_interface="WLAN"
echo 设置IP、网关中...
netsh interface ip set address "%net_interface%" static 192.168.18.166 255.255.255.0 192.168.18.1
echo 设置DNS中...
netsh interface ip set dns "%net_interface%" static 223.5.5.5
echo IP已成功切换至居家模式,任意键返回...
pause>nul
goto start
 
:dhcp
cls
echo.
echo 正在切换至无所谓模式(DHCP)请等待...
echo.
set net_interface="WLAN"
echo 设置IP、网关中...
netsh interface ip set address "%net_interface%" dhcp
echo 设置DNS中...
netsh interface ip set dns "%net_interface%" dhcp
echo IP已成功切换至无所谓模式,任意键返回...
pause>nul
goto start

复制保存至.bat文件即可。

注意:net_interface=“WLAN”,需调整为实际网卡名称
在这里插入图片描述
另外运行时需右键“以管理员身份运行” 运行,不然会提示“请求的操作需要提升(作为管理员运行)。”
在这里插入图片描述

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐