虽然已经解决了,还是补上一个用批处理实现的吧- @echo off&setlocal ENABLEDELAYEDEXPANSION
- for /f "tokens=1* delims=:" %%a in ('ipconfig ^|findstr /c:"IP Add"') do set ip=%%b
- echo 你的IP是: %ip%
- for /f "tokens=1-4 delims=. " %%1 in ("%ip%") do (
- set v1=00%%1
- set v2=00%%2
- set v3=00%%3
- set v4=00%%4
- set ipx=!v1:~-3!.!v2:~-3!.!v3:~-3!.!v4:~-3!
- )
-
- echo 补0后是: %ipx%
- for /f "usebackq tokens=1-3 delims==~~" %%a in ("%~0") do (
- if defined find (
- set /a n+=1
- set ve=00%%b
- for /f "tokens=1-4 delims=." %%1 in ("%%a") do (
- set v1=00%%1
- set v2=00%%2
- set v3=00%%3
- set v4=00%%4
- set op!n!=!v1:~-3!.!v2:~-3!.!v3:~-3!.!v4:~-3! !v1:~-3!.!v2:~-3!.!v3:~-3!.!ve:~-3! %%c
- )
- rem 给每个IP区域弃置都补0
-
- ) else (
- if "%%a" equ "[config]" set find=y
- )
- )
-
-
- for /l %%k in (1,1,%n%) do (
- for /f "tokens=1-3" %%a in ("!op%%k!") do (
- if "!ipx!" geq "%%a" if "!ipx!" leq "%%b" set run=%%c&goto :run
- )
- )
- rem 然后逐个比较,有匹配的区域则中断比较,跳到运行段
- pause
-
-
- goto :eof
-
- :run
- echo;RUN %run%
- pause
- goto :eof
-
-
- 配置区
- [config]
- 192.168.1.2~26=1.exe
- 192.168.1.27~86=2.exe
- 192.168.1.87~186=3.exe
- 192.168.2.2~86=4.exe
- 192.168.2.87~196=6.exe
复制代码
|