Windows bat脚本设置静态IP&DNS和动态IP&DNS

2020-01-06 2009点热度 0人点赞 0条评论

办公室.bat(静态IP)

@echo off
%1 mshta vbscript:CreateObject("Shell.Application").ShellExecute("cmd.exe","/c %~s0 ::","","runas",1)(window.close)&&exit
cd /d "%~dp0"
netsh interface ip set address "以太网" static 192.168.2.172 255.255.255.0 192.168.2.1
netsh interface ip set dns name="以太网" source=static addr=10.11.3.22

家里.bat(动态获取IP)

@echo off
%1 mshta vbscript:CreateObject("Shell.Application").ShellExecute("cmd.exe","/c %~s0 ::","","runas",1)(window.close)&&exit
cd /d "%~dp0"
netsh interface ip set address "以太网" source=dhcp
netsh interface ip set dns name="以太网" source=dhcp

合并到一个脚本中

@echo off
echo       ===========================================
echo             请选择要进行的操作,然后按回车
echo       ===========================================
echo.
echo             S.修改ip为内网ip,并设置代理
echo.
echo             R.恢复ip为动态ip,并关闭代理
echo.
echo             Q.退出
echo.
echo.
echo.

:loop_start
set /p choice=    请选择:
IF NOT "%choice%"=="" SET choice=%choice:~0,1%
if /i "%choice%"=="S" goto set_start
if /i "%choice%"=="R" goto reset_start
if /i "%choice%"=="Q" goto closee
echo 选择无效,请重新输入
echo.
goto loop_start

::====================================================================================

:set_start
echo  设置IP地址....
netsh interface ip set addr "以太网" static 192.168.2.22 255.255.255.0 192.168.2.1 1
echo  设置DNS地址....
netsh interface ip set dns "以太网" static 180.76.76.76 primary validate=no
echo *****设置成功!您的IP已修改为内网ip
echo.


goto endd

::====================================================================================

:reset_start
echo  恢复IP地址....
netsh interface ip set addr "以太网" dhcp
echo  恢复DNS地址....
netsh interface IP set dns "以太网" dhcp
echo *****设置成功!您的IP已恢复为动态ip
echo.
goto endd

::====================================================================================

:endd
pause
:closee

王显锋

激情工作,快乐生活!

文章评论