IP配置切换
@echo off
rem 强制获取管理员权限
%1 mshta vbscript:CreateObject("Shell.Application").ShellExecute("cmd.exe","/c %~s0 ::","","runas",1)(window.close)&&exit
rem //设置网卡变量 修改net2为你使用的网卡名
set NAME="net2"
rem //MA区域以下属性值可以根据需要更改
set ADDR=1.1.1.1
set MASK=255.255.255.0
set GATEWAY=1.1.1.1
set DNS1=
set DNS2=
rem //以上属性依次为IP地址、子网掩码、网关、首选DNS、备用DNS
rem //DP区域以下属性值可以根据需要更改
set DP_ADDR=2.2.2.2
set DP_MASK=255.255.255.0
set DP_GATEWAY=2.2.2.2
set DP_DNS1=
set DP_DNS2=
rem //以上属性依次为IP地址、子网掩码、网关、首选DNS、备用DNS
echo 网络配置切换器:
echo 1 设置为静态IP (MA1)
echo 2 设置为静态IP (DP1)
echo 3 设置为动态IP
echo 4 退出
echo 请选择后回车:
set /p operate=
if %operate%==1 goto 1
if %operate%==2 goto 2
if %operate%==3 goto 3
if %operate%==4 goto 4
:1
echo 正在设置静态IP,请稍等...
rem //可以根据你的需要更改
echo MAIP地址 = %ADDR%
echo MA掩码 = %MASK%
echo MA网关 = %GATEWAY%
netsh interface ipv4 set address %NAME% static %ADDR% %MASK% %GATEWAY%
echo MA首选DNS = %DNS1%
if "%DNS1%"=="" (echo DNS1为空) else netsh interface ipv4 set dns %NAME% static %DNS1%
echo MA备用DNS = %DNS2%
if "%DNS2%"=="" (echo DNS2为空) else (netsh interface ipv4 add dns %NAME% %DNS2%)
rem //netsh interface set interface %NAME disabled
echo **********MA已设置为静态IP:%ADDR%***********
pause
goto 4
:2
echo 正在设置静态IP,请稍等...
rem //可以根据你的需要更改
echo IP地址 = %DP_ADDR%
echo 掩码 = %DP_MASK%
echo 网关 = %DP_GATEWAY%
netsh interface ipv4 set address %NAME% static %DP_ADDR% %DP_MASK% %DP_GATEWAY%
echo 首选DNS = %DNS1%
if "%DP_DNS1%"=="" (echo DNS1为空) else netsh interface ipv4 set dns %DP_NAME% static %DP_DNS1%
echo 备用DNS = %DNS2%
if "%DP_DNS2%"=="" (echo DNS2为空) else (netsh interface ipv4 add dns %DP_NAME% %DP_DNS2%)
rem //netsh interface set interface %NAME disabled
echo **********DP已设置为静态IP:%DP_ADDR%***********
pause
goto 4
:3
echo 正在设置动态IP,请稍等...
echo 正在从DHCP自动获取IP地址...
netsh interface ip set address %NAME% dhcp
echo 正在从DHCP自动获取DNS地址...
netsh interface ip set dns %NAME% dhcp
echo **********已设置为动态IP地址***********
pause
goto 4
:4
rem //netsh interface set interface %NAME enabled
echo by:iXiAo9,请稍等...
exit
自动连接WiFi脚本
@echo off
echo WIFI自动重连服务正在进行中.......
echo 停止服务请按 Ctrl+C
:begin
echo %date% %time%
ping baidu.com
rem echo %errorlevel%
if %errorlevel%==1 goto ping2
goto loop
:ping2
ping 202.118.66.6
rem echo %errorlevel%
if %errorlevel%==1 goto reconnect
goto loop
:reconnect
echo %date% %time% 网络主动断开
netsh wlan disconnect
echo %date% %time% 正在重新连接中....
rem //Network修改为你的WiFi名称
netsh wlan connect ssid=Network name=Network
echo %date% %time% 已发送连接请求....ssid=Network
goto loop
:loop
timeout 600
goto begin
标签:脚本,常用,set,netsh,Win,echo,rem,interface,DP
From: https://www.cnblogs.com/iXiAo9/p/16634745.html