:d
echo 您选择了手动配置IP,请按提示输入。。。
echo.
set /p ADDR=IP地址:
set /p MASK=子网掩码:
set /p GATEWAY=默认网关:
set /p DNS1=首选DNS:
set /p DNS2=备用DNS:
echo --------------------------------
echo 开始设置网卡.....
netsh interface ip set address name="本地连接" static %IP% %MASK% %GATEWAY% 0
echo 开始设置首选DNS......
netsh interface ip set dns name="本地连接" static %DNS1% primary
echo 开始设置备用DNS....
netsh interface ip add dns name="本地连接" %DNS2%

批处理修改IP地址,选择手动设置IP出现以下错误:

子网掩码255.255.255.0是不可接受的?

以下是该批处理文件的代码,除了选择手动设置出现上述错误外,其他选择可正常运行!

@echo off
cls
color 0A
echo **********************************
echo  快速切换IP,请选择应用环境:
echo  1、宽带拨号,充当主机
echo  2、客户机上网
echo  3、自动获取IP,独自拨号上网(×××)
echo  4、手动设置IP
echo **********************************

set /p KEY=请输入您的选择:

echo.
echo 正在更改IP,请稍等数秒。。。

if %KEY% == 1 goto a
if %KEY% == 2 goto b
if %KEY% == 3 goto c
if %KEY% == 4 goto d

:a
netsh interface ip set address "本地连接" static 192.168.123.23 255.255.255.0 192.168.123.23 1
netsh interface ip set dns name="本地连接" source=dhcp
goto exit

:b
netsh interface ip set address name="本地连接" static 192.168.123.223 255.255.255.0 192.168.123.23 1
netsh interface ip set dns name="本地连接" source=dhcp
goto exit

:c
netsh interface ip set address name="本地连接" source=dhcp
netsh interface ip set dns name="本地连接" source=dhcp
goto exit

:d
echo 您选择了手动配置IP,请按提示输入。。。
echo.
set /p ADDR=IP地址:
set /p MASK=子网掩码:
set /p GATEWAY=默认网关:
set /p DNS1=首选DNS:
set /p DNS2=备用DNS:
echo --------------------------------
echo 开始设置网卡.....
netsh interface ip set address name="本地连接" static %IP% %MASK% %GATEWAY% 0
echo 开始设置首选DNS......
netsh interface ip set dns name="本地连接" static %DNS1% primary
echo 开始设置备用DNS....
netsh interface ip add dns name="本地连接" %DNS2%

:exit
echo 更改IP成功,如有冲突请重新运行程序修改。。。
pause