前言:
生活中有遇到不同的场景下需要更换IP,手动设置比较麻烦
1.一键设置网卡DHCP 自动获取IP地址
首先打开本地连接,更改要修改网卡的名称 建议修改成英文
改好如下图
新建记事本 改后缀 *.bat
复制下内容
%1 mshta vbscript:CreateObject("Shell.Application").ShellExecute("cmd.exe","/c %~s0 ::","","runas",1)(window.close)&&exit cd /d "%~dp0" netsh interface ip set address "network" dhcp
2.设置网卡为静态固定IP地址
其他设置参考上方法
%1 mshta vbscript:CreateObject("Shell.Application").ShellExecute("cmd.exe","/c %~s0 ::","","runas",1)(window.close)&&exit cd /d "%~dp0" netsh interface ip set address "network" static 192.168.1.201 255.255.0.0
3.进阶手动选择修改项
%1 mshta vbscript:CreateObject("Shell.Application").ShellExecute("cmd.exe","/c %~s0 ::","","runas",1)(window.close)&&exit cd /d "%~dp0" @echo off echo 1 内网 echo 2 外网 set /p answer= if %answer%==1 goto 1 if %answer%==2 goto 2 :1 netsh interface ip set address "network" static 192.168.1.201 255.255.0.0 pause goto end :2 netsh interface ip set address "network" dhcp
如下图 手动输入进行切换
4.进阶进阶,加上了提示内容
%1 mshta vbscript:CreateObject("Shell.Application").ShellExecute("cmd.exe","/c %~s0 ::","","runas",1)(window.close)&&exit cd /d "%~dp0" @echo off echo 1 static echo 2 dhcp set /p answer= if %answer%==1 goto 1 if %answer%==2 goto 2 :1 @echo off cls color 0A Echo ******************************************************************************* Echo 正在修改IP地址和DNS服务器地址,请耐心等待………… Echo ******************************************************************************* netsh interface ip set address name="network" source=static addr=192.168.11.125 mask=255.255.255.0 ipconfig /all Echo ******************************************************************************* Echo OK!!已修改成功!请按任意键继续………… Echo ******************************************************************************* pause goto end :2 @echo off cls color 0A Echo ******************************************************************************* Echo 正在修改IP地址和DNS服务器地址,请耐心等待………… Echo ******************************************************************************* netsh interface ip set address name="network" source=dhcp netsh interface ip delete dns "network" all ipconfig /flushdns ipconfig /all Echo ******************************************************************************* Echo OK!!已修改成功!请按任意键继续………… Echo ******************************************************************************* Pause