@echo off
setlocal enabledelayedexpansion
color 71
%1 start "" mshta vbscript:CreateObject("Shell.Application").ShellExecute("cmd.exe","/c pushd ""%~dp0"" && ""%~s0"" ::","","runas",1)(window.close)&&exit
:: 定义IP地址、子网掩码和网关
set "ip1=10.18.60.147"
set "mask1=255.255.255.0"
set "gateway1=10.18.60.1"
set "ip2=172.2.2.147"
set "mask2=255.255.255.0"
set "gateway2=172.2.2.1"
set dns1=10.10.0.4
set dns2=10.10.0.6
:: 获取当前IP地址和网关
for /f "tokens=2 delims=:" %%i in ('ipconfig ^| findstr "IPv4"') do (
set "current_ip=%%i"
)
for /f "tokens=2 delims=:" %%j in ('ipconfig ^| findstr "Default"') do (
set "current_gateway=%%j"
)
:: 提示用户选择IP地址和网关
echo 请选择要设置的IP地址和网关:
echo 1. IP地址 %ip1% 和网关 %gateway1%
echo 2. IP地址 %ip2% 和网关 %gateway2%
set /p choice=请输入选择编号(1或2):
echo choice选择:%choice%
:: 根据用户选择设置相应的IP地址和网关
if %choice%==1 (
echo IP地址和网关选择:%ip1% 和 %gateway1%
netsh interface ipv4 set address name="以太网" source=static address=%ip1% mask=%mask1% gateway=%gateway1% 1>nul
:: netsh interface ipv4 set dns name="以太网" source=static address=8.8.8.8 primary 1>nul
:: 设置首选DNS服务器
netsh interface ipv4 add dnsservers name="以太网" address=%dns1% index=1 validate=no
:: 设置备用DNS服务器
netsh interface ipv4 add dnsservers name="以太网" address=%dns2% index=2 validate=no
) else if %choice%==2 (
echo IP地址和网关选择:%ip2% 和 %gateway2%
netsh interface ipv4 set address name="以太网" source=static address=%ip2% mask=%mask2% gateway=%gateway2% 1>nul
:: 设置首选DNS服务器
netsh interface ipv4 add dnsservers name="以太网" address=%dns1% index=1 validate=no
:: 设置备用DNS服务器
netsh interface ipv4 add dnsservers name="以太网" address=%dns2% index=2 validate=no
) else (
echo 无效的选择,请输入正确的编号(1或2)。
)
timeout /t 5 >nul
echo -----------------------------
echo - 网络参数设置完成 -
echo -----------------------------
echo -----------------------------
pause