windows下自动更改IP的小工具(bat批处理文件)

每次上线,都要先上灰度环境再上到正式环境。在上到灰度环境时,访问灰度环境通过自动获取IP和更改指定dns来实现。具体如何实现,大家可自行百度。

新建一个文本文档,将其后缀改为bat,打开该文件,拷贝一下代码:

@echo off
:start
echo ============请输入数字选择下一步操作:
echo ============1:ip设置为灰度
echo ============2:ip设置为原IP
set /P var=":"
if %var%==1 goto ip10
if %var%==2 goto ip172
:ip10
cls
echo **正在将IP设置为灰度......**
netsh interface ip set address name="本地连接" source=dhcp
netsh interface ip delete dns "本地连接" all
ipconfig /flushdns
cmd /c netsh interface ip set dns name="本地连接" source=static addr=192.168.0.216 register=primary 
echo **成功将IP设置为灰度**
echo ------------------------------------------
goto start
:ip172
cls
echo **正在将IP还原......**
netsh interface ip set address name="本地连接" source=static addr=192.168.1.132 mask=255.255.255.0 gateway=192.168.3.254
cmd /c netsh interface ip set dns name="本地连接" source=static addr=180.76.76.76 register=primary 
cmd /c netsh interface ip add dns name="本地连接" addr=8.8.8.8 index=2
echo **成功将IP还原为192.168.1.132**
echo ------------------------------------------
goto start

猜你喜欢

转载自blog.csdn.net/xu547823501/article/details/85858913
今日推荐