如何用批处理设置IP地址

2024-10-31 02:22:19
推荐回答(3个)
回答1:

可以内外可以同时上。

回答2:

用netsh命令编写

回答3:

@echo off
REM 选项:
:choice
echo 输入1,网卡IP将被设置成192.168.1.5,输入2,网卡IP将被设置成10.96.236.6
set /p select=请输入您的选择:
if not %select%==1 if not %select%==2 cls&echo 您的输入错误,请重新输入!&echo.&goto choice

REM 获取网卡名称
for /f "skip=4 tokens=3* delims= " %%i in ('ipconfig') do (
set adapter=%%i
goto out
)

:out
set adapter=%adapter::=%
if %select%==1 (
netsh int ip set address name="%adapter%" static 192.168.1.5 255.255.255.0 192.168.1.1 1
netsh int ip set dns name="%adapter%" static 202.96.123.6 primary
netsh int ip add dns name="%adapter%" 201.99.224.8 index=2
) else (
netsh int ip set address name="%adapter%" static 10.96.236.6 255.255.255.0 10.96.236.1 1
)

echo 设置完成,按任意键退出!
pause >nul 2>nul