- @echo off
- title 取IP
- :: By:Neko Piao, 2017-05-25
-
- set fileName=iennfr2012.drv
- ::set fileName=%1
-
- ::取第 一 行
- setlocal enabledelayedexpansion
- for /f "tokens=1 delims=" %%i in (%fileName%) do (
- set /a n+=1
- if !n!==1 set Line_of_text=%%i
- )
- setlocal disabledelayedexpansion
- set /a n=0
- ::不要问我为什么这个set在这里,遇到过莫名bug要放到这里重置.虽然这次不需要,不过也不妨碍什么,请让它就在这里吧owo
-
- ::取前后字段
- for /f "tokens=2 delims==" %%a in ("%Line_of_text%") do (
- set "ip=%%a")
-
- for /f "tokens=1-4 delims=." %%a in ("%ip%") do (
- set "ip_1=%%a"&set "ip_2=%%b"&set "ip_3=%%c"&set "ip_4=%%d"
- )
-
- echo %ip_1%.%ip_2%.%ip_3%.%ip_4%
- pause
复制代码
|