Я возился. Не спрашивайте меня, почему ... но вот довольно обширная проверка вашего ipaddress/gateway/subnet-mask:
@Echo Off
set NEW-IPADDR=192.168.1.2
set NEW-MASK=255.255.255.240
set NEW-GW=192.168.1.1
set RETURN=isValidIP
goto checkIP
:isValidIP
echo.We are good to go.
REM ---------------------------------------------------------------------
REM Do whatever with the IP/mask/GW here. The values appear to be valid.
REM ---------------------------------------------------------------------
goto :End
:checkIP
for /f "tokens=1,2,3,4 delims=. " %%a in ("%NEW-IPADDR%") do set ip1=%%a&set ip2=%%b&set ip3=%%c&set ip4=%%d
set /a decIP=(16777216*%ip1%)+(65536*%ip2%)+(256*%ip3%)+%ip4% 2> nil
for /f "tokens=1,2,3,4 delims=. " %%a in ("%NEW-MASK%") do set mask1=%%a&set mask2=%%b&set mask3=%%c&set mask4=%%d
set /a decMask=(16777216*%mask1%)+(65536*%mask2%)+(256*%mask3%)+%mask4% 2> nil
set /a netAddr="%decIP%&%decMask%" 2> nil
for /f "tokens=1,2,3,4 delims=. " %%a in ("%NEW-GW%") do set gw1=%%a&set gw2=%%b&set gw3=%%c&set gw4=%%d
set /a decGW=(16777216*%gw1%)+(65536*%gw2%)+(256*%gw3%)+%gw4% 2> nil
set /a gwNetAddr="%decGW%&%decMask%" 2> nil
set isBadLabel=badIP
if %ip1% EQU 127 (goto :badIP)
if %ip1% EQU 0 (goto :badIP)
set num=%ip1%
call :checkNum
if %badNum% equ 1 (goto :End)
set num=%ip2%
call :checkNum
if %badNum% equ 1 (goto :End)
set num=%ip3%
call :checkNum
if %badNum% equ 1 (goto :End)
set num=%ip4%
call :checkNum
if %badNum% equ 1 (goto :End)
set isBadLabel=badMask
set num=%mask1%
call :checkNum
if %badNum% equ 1 (goto :End)
set num=%mask2%
call :checkNum
if %badNum% equ 1 (goto :End)
set num=%mask3%
call :checkNum
if %badNum% equ 1 (goto :End)
set num=%mask4%
call :checkNum
if %badNum% equ 1 (goto :End)
set isBadLabel=badGW
set num=%gw1%
call :checkNum
if %badNum% equ 1 (goto :End)
set num=%gw2%
call :checkNum
if %badNum% equ 1 (goto :End)
set num=%gw3%
call :checkNum
if %badNum% equ 1 (goto :End)
set num=%gw4%
call :checkNum
if %badNum% equ 1 (goto :End)
set testmask=-2
set bcast=0
:loopmask
set /a testmask=%testmask%+%testmask%
if %decmask% EQU %testmask% (set bcast=%testmask%)
if %bcast% neq 0 (goto :goodMask)
if %testmask% geq -16777216 (goto :loopmask)
:badMask
echo.Bad subnet mask. (%NEW-MASK%) Check and try again.
echo.
goto :End
:badIP
echo.Bad IP Address. (%NEW-IPADDR%) Check and try again.
echo.
goto :End
:goodMask
set /a bcast="%bcast%^-1"
set /a bcast=%netAddr%+%bcast%
if %decIP% equ %bcast% (goto :badIP)
if %decIP% equ %decGW% (goto :badGW)
if %gwNetAddr% neq %netAddr% (goto :badGW)
if %decGW% equ %bcast% (goto :badGW)
if %decGW% equ %netAddr% (goto :badGW)
goto :goodGW
:badGW
echo.Bad Gateway Address. (%NEW-GW%) Check and try again.
echo.
goto :End
:goodGW
goto %RETURN%
goto :End
:checkNum
set badNum=0
set /a numval=%num% 2> nil
if "z%num%" neq "z%numval%" (set badNum=1) else (
if %num% GTR 255 (set badNum=1) else (
if %num% LSS 0 (set badNum=1)
)
)
if %badNum% equ 1 (goto %isBadLabel%)
goto :EOF
:End
Это даже работает в Vista, и 7.
---- whops забыл проверить, является ли шлюз сетевым адресом / широковещательным адресом. ----