:enda
echo %yy%
set /p uu=输入子网掩码(格式:255.255.255.0):
echo %uu%|findstr "^[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*$">nul||goto failb
set _uu=%uu:.= %
call :checkb %_uu%
goto end
:checkb
if "%4"=="" goto failb
if "%1"=="0" goto failb
if %4 gtr %3 goto failb
if %3 gtr %2 goto failb
if %2 gtr %1 goto failb
for %%u in (%1 %2 %3 %4) do (if %%u gtr 255 goto failb
for %%t in (0,128,192,224,240,248,252,254,255) do (if "%%u"=="%%t" goto endb)
goto failb)
:failb
::cls
echo %uu%是错误的子网掩码!!
echo.
pause
goto enda
:endb
:end
这段代码为什么%U只执行一遍??
运行后:
C:\>echo
ECHO 处于打开状态。
C:\>set /p uu=输入子网掩码(格式:255.255.255.0):
输入子网掩码(格式:255.255.255.0):255.255.255.1
C:\>echo 255.255.255.1 | findstr "^[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*$" 1>nul || g
oto failb
C:\>set _uu=255 255 255 1
C:\>call :checkb 255 255 255 1
C:\>if "1" == "" goto failb
C:\>if "255" == "0" goto failb
C:\>if 1 GTR 255 goto failb
C:\>if 255 GTR 255 goto failb
C:\>if 255 GTR 255 goto failb
C:\>for %u in (255 255 255 1) do (
if %u GTR 255 goto failb
for %t in (0 128 192 224 240 248 252 254 255) do (if "%u" == "%t" goto endb )
goto failb
)
C:\>(
if 255 GTR 255 goto failb
for %t in (0 128 192 224 240 248 252 254 255) do (if "255" == "%t" goto endb )
goto failb
)
C:\>(if "255" == "0" goto endb )
C:\>(if "255" == "128" goto endb )
C:\>(if "255" == "192" goto endb )
C:\>(if "255" == "224" goto endb )
C:\>(if "255" == "240" goto endb )
C:\>(if "255" == "248" goto endb )
C:\>(if "255" == "252" goto endb )
C:\>(if "255" == "254" goto endb )
C:\>(if "255" == "255" goto endb )
C:\>goto end