@echo off
:: 检测IP格式是否标准
:: code by jm 2006-10-23
:begin
cls
set input=
set /p input=请输入IP:
echo %input%|findstr "^[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*$">nul||goto fail
set _input=%input:.= %
call :check %_input%
:check
if "%4"=="" goto fail
for %%i in (%1 %2 %3 %4) do (
if %%i gtr 255 goto fail
)
cls
echo %input% 是正确的IP
echo.
pause
goto begin
:fail
cls
echo %input% 是错误的IP
echo.
pause
goto begin
这段代码如何改才能实现只判断一次就退出?? 偶改完后发现如果IP正确要再判断一次!
改后:
@echo off
:: 检测IP格式是否标准
:: code by jm 2006-10-23
:begin
cls
set input=
set /p input=请输入IP:
echo %input%|findstr "^[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*$">nul||goto fail
set _input=%input:.= %
call :check %_input%
:check
if "%4"=="" goto fail
for %%i in (%1 %2 %3 %4) do (
if %%i gtr 255 goto fail
)
cls
echo %input% 是正确的IP
echo.
pause
goto end
:fail
cls
echo %input% 是错误的IP
echo.
pause
:end
[ Last edited by lg560852 on 2007-7-27 at 11:26 AM ]作者: lg560852 时间: 2007-7-27 11:26 这是偶又调试时的情况
修改后:
::@echo off
:: 检测IP格式是否标准
:: code by jm 2006-10-23
:begin
::cls
set input=
set /p input=请输入IP:
echo %input%|findstr "^[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*$">nul||goto fail
set _input=%input:.= %
call :check %_input%
:check
if "%4"=="" goto fail
for %%i in (%1 %2 %3 %4) do (
if %%i gtr 255 goto fail
)
::cls
echo %input% 是正确的IP
echo.
pause
goto end
:fail
::cls
echo %input% 是错误的IP
echo.
pause
:end
执行结果:
C:\Documents and Settings\桌面>set input=
C:\Documents and Settings\桌面>set /p input=请输入IP:
请输入IP:1.1.1.1