Board logo

标题: [文本处理] 批处理如何截取指定的字符串? [打印本页]

作者: xiaolijian916    时间: 2015-11-15 20:55     标题: 批处理如何截取指定的字符串?

以下代码已经获取到了所有的IPV4的IP地址:
  1. wmic nicconfig get IPAddress /value | findstr /i "IPAddress=[^]"
  2. pause
复制代码
执行结果如下:
  1. C:\Users\Administrator\Desktop>wmic nicconfig get IPAddress /value   | findstr /i "IPAddress=[^]"
  2. IPAddress={"192.168.1.2","fe80::7146:d78a:87be:2fae"}
  3. IPAddress={"10.0.132.181","fe80::6dee:c2a2:649d:96df"}
复制代码
能不能将192.168.1.2和10.0.132.181提取出来,并显示为两行,如下所示:
  1. -------------------------------------------------
  2. |  本机局域网IP地址 |         192.168.1.2         |
  3. -------------------------------------------------
  4. |  本机以太网IP地址 |         10.0.132.181        |
  5. -------------------------------------------------
复制代码

作者: terse    时间: 2015-11-15 21:19

  1. @echo off&setlocal enabledelayedexpansion
  2. for /f "skip=1delims={,}" %%i in ('wmic nicconfig get IPAddress') do (
  3.      for /f %%j in (%%i) do set /a n+=1&set "IPAddress_!n!=%%j"
  4. )
  5. for /l %%i in (1,1,%n%) do echo "!IPAddress_%%i!"
  6. pause
复制代码

作者: ads350668398    时间: 2015-11-15 23:43

C:\Users\Administrator\Desktop\双色球>wmic nicconfig get IPAddress /value   | fi
ndstr /i "IPAddress=[^]"
IPAddress={"192.168.1.100","fe80::497c:8a36:706:8a78"}

C:\Users\Administrator\Desktop\双色球>pause
请按任意键继续. . .
***********
我的执行结果为什么 没有外网IP??
作者: terse    时间: 2015-11-15 23:54

回复 3# ads350668398
局域网吧 路由?
作者: ads350668398    时间: 2015-11-16 00:12

我是自己家 用上了路由器
作者: 依山居    时间: 2015-11-16 02:18

  1. wmic nicconfig get  IPAddress  /value|f -r:"(\d{1,3}\.\d{1,3}\.\d{1,3})\.\d{1,3}" -o:k -stdin
复制代码
http://baiy.cn/utils/f/index.htm




欢迎光临 批处理之家 (http://www.bathome.net/) Powered by Discuz! 7.2