Batch processing to check whether IP format is correct

Time:2021-1-13

Copy codeThe code is as follows:
@echo off
: check whether the IP format is standard
:: code by jm 2006-10-23
:begin
cls
set input=
Set / P input = please 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% is the correct IP
echo.
pause
goto begin

:fail
cls
Echo% input% is the wrong IP
echo.
pause
goto begin