我做了一个稍微复杂的脚本。你应该从命令行调用它:<script.cmd> IP
例如。<script.cmd> 192.168.1.4
.
@echo off &setlocal enabledelayedexpansion
set "var=%~1"
set "flag="
for /f "tokens=1-4delims=." %%i in ("%var%") do set /a var1=%%i, var2=%%j, var3=%%k, var4=%%l
for /l %%i in (1,1,4) do if %%i neq 1 (set "var0=!var0!.!var%%i!") else set "var0=!var%%i!"
for /l %%i in (1,1,4) do if "!var%%i!" equ "" set "flag=1"
if not defined flag for /l %%i in (1,1,4) do if !var%%i! lss 0 set "flag=1"
if not defined flag for /l %%i in (1,1,4) do if !var%%i! gtr 255 set "flag=1"
if defined flag (echo "%var0%" is NOT a valid IP.) else echo "%var0%" is a valid IP.
endlocal