本帖最后由 mxxcgzxxx 于 2011-6-27 21:12 编辑
2# 601997526
首段不能为0
尾段不能为0或255
不过受启发,改如下- @echo off
- set "ip1=^2[0-5][0-5]$ ^1[0-9][0-9]$ ^[1-9][0-9]$ ^[1-9]$"
- set "ip2=^2[0-5][0-5]$ ^1[0-9][0-9]$ ^[1-9][0-9]$ ^[0-9]$"
- set "ip3=^2[0-5][0-4]$ ^1[0-9][0-9]$ ^[1-9][0-9]$ ^[1-9]$"
- :ip
- cls
- set/p ip=请输入IP(如:192.168.1.1)
- echo %ip%|findstr "^[0-9]*.[0-9]*.[0-9]*.[0-9]*$"||goto :ip
- for /f "tokens=1,2,3,4 delims=." %%i in ("%ip%") do (
- echo %%i|findstr "%ip1%"||goto :ip
- echo %%j|findstr "%ip2%"||goto :ip
- echo %%k|findstr "%ip2%"||goto :ip
- echo %%l|findstr "%ip3%"||goto :ip
- )
- echo 正确
- pause>nul
- goto :ip
复制代码 能再提供多点思路吗
加强版,解决问题4,识别用时0.58秒- @echo off
- set "ip1=^10$ ^172$ ^192$"
- set "ip2=^2[0-5][0-5]$ ^1[0-9][0-9]$ ^[1-9][0-9]$ ^[0-9]$"
- set "ip3=^2[0-5][0-4]$ ^1[0-9][0-9]$ ^[1-9][0-9]$ ^[1-9]$"
- set "ip4=^1[6-9]$ ^2[0-9]$ ^3[0-1]$"
-
- :ip
- cls
- set/p ip=请输入IP(如:192.168.1.1)
- echo %ip%|findstr "^[0-9]*.[0-9]*.[0-9]*.[0-9]*$">nul||pause&&goto :ip
- for /f "tokens=1,2,3,4 delims=." %%i in ("%ip%") do (
- echo %%i|findstr "%ip1%">nul||goto :ip
- echo %%k|findstr "%ip2%">nul||goto :ip
- echo %%l|findstr "%ip3%">nul||goto :ip
- if %%i==10 echo %%j|findstr "%ip2%">nul||goto :ip
- if %%i==172 echo %%j|findstr "%ip4%">nul||goto :ip
- if %%i==192 echo %%j|findstr "^168$">nul||goto :ip
- )
- echo 正确
- pause>nul
- goto :ip
复制代码
|