标题: 【求助】从ipconfig命令输出中提取ip地址
[打印本页]
作者: ruson07
时间: 2010-12-10 11:21
标题: 【求助】从ipconfig命令输出中提取ip地址
实在是有点急了,自己写了一个不管用,求助大虾!
需求:从ipconfig命令的输出中提出需要的以192.168.1.10开始的ip地址,例如:可能有192.168.1.1和192.168.1.100,那么需要提取出192.168.1.100,然后将该ip地址存入到某一变量中保存,以做后用。
下面是一段ipconfig可能的输出结果:(***注意,其中会有空行)
-----------------------------------------------
D:\>ipconfig
Windows IP Configuration
Ethernet adapter Local Area Connection:
Connection-specific DNS Suffix . : users.bbs.com
IP Address. . . . . . . . . . . . : 10.21.5.1
Subnet Mask . . . . . . . . . . . : 255.255.252.0
IP Address. . . . . . . . . . . . : fe80::21f:e2ff:fe10:54c1%4
Default Gateway . . . . . . . . . : 10.21.7.254
Ethernet adapter Local Area Connection 9:
Connection-specific DNS Suffix . :
IP Address. . . . . . . . . . . . : 192.168.1.100
Subnet Mask . . . . . . . . . . . : 255.255.255.0
IP Address. . . . . . . . . . . . : fe80::5a2c:80ff:fe13:9263%7
Default Gateway . . . . . . . . . : 192.168.1.1
Tunnel adapter Teredo Tunneling Pseudo-Interface:
Connection-specific DNS Suffix . :
IP Address. . . . . . . . . . . . : fe80::ffff:ffff:fffd%5
Default Gateway . . . . . . . . . :
Tunnel adapter Automatic Tunneling Pseudo-Interface:
Connection-specific DNS Suffix . :
IP Address. . . . . . . . . . . . : fe80::5efe:192.168.1.100%2
Default Gateway . . . . . . . . . :
Tunnel adapter Automatic Tunneling Pseudo-Interface:
Connection-specific DNS Suffix . : users.bbs.com
IP Address. . . . . . . . . . . . : fe80::5efe:10.21.5.1%2
Default Gateway . . . . . . . . . :
-----------------------------------------------------------------------
谢谢!
[
Last edited by ruson07 on 2010-12-10 at 11:24 ]
作者: Hanyeguxing
时间: 2010-12-10 14:04
@echo off&setlocal enabledelayedexpansion
for /f "tokens=2 delims=:" %%a in ('ipconfig/all^|find /i "ip address"') do (
set a=%%a
if "!a:~0,13!"==" 192.168.1.10" (
set/a n+=1
set ip_!n!=!a:~1,-1!
))
如果只有一个,则变量名为ip_1,否则继续为ip_2,ip_3等,范围由变量n决定
如果确定只有一个则:
[code]@echo off&setlocal enabledelayedexpansion
for /f "tokens=2 delims=:" %%a in ('ipconfig/all^|find /i "ip address"') do (
set a=%%a
if "!a:~0,13!"==" 192.168.1.10" set ip=!a:~1,-1!
)
作者: bailang3106
时间: 2010-12-12 14:47
我仿照这个 写出了自己的批处理 谢谢
作者: ruson07
时间: 2010-12-14 16:47
非常感谢!!!