Board logo

标题: [求助]BAT如何获取这几个字符 [打印本页]

作者: bing614     时间: 2007-5-4 10:56    标题: [求助]BAT如何获取这几个字符
使用ipconfig/all得到如下:

-----------------------------------------------------
Windows IP Configuration

Host Name . . . . . . . . . . . . : Join
Primary Dns Suffix . . . . . . . :
Node Type . . . . . . . . . . . . : Unknown
IP Routing Enabled. . . . . . . . : No
WINS Proxy Enabled. . . . . . . . : No

Ethernet adapter 本地连接:


Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : Realtek RTL8139/810x Family Fast Ethernet NIC

Physical Address. . . . . . . . . : 00-11-09-89-1B-C4
Dhcp Enabled. . . . . . . . . . . : No
IP Address. . . . . . . . . . . . : 192.168.0.1
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.0.254
DNS Servers . . . . . . . . . . . : 202.96.128.143
202.96.128.86
202.96.128.68
202.96.128.166

----------------------------------------------------------------------------------------------------------
我想获取次DNS:202.96.128.86以及后面的202.96.128.143,202.96.128.166.应该怎么写,请指教.

作者: slore     时间: 2007-5-4 11:42
看下tokens的用法

作者: bing614     时间: 2007-5-4 12:48
有没有代码演示一下

作者: qq43142691     时间: 2007-5-4 13:17
什么意思啊。。。你要什么字符啊?

作者: bing614     时间: 2007-5-4 15:15
我想获取后备DNS
202.96.128.86
202.96.128.68
202.96.128.166

作者: ansipeter     时间: 2007-5-4 15:45
楼主试试下面的代码:

@echo off&setlocal
for /f "delims=: tokens=1,2" %%a in ('ipconfig/all^|findstr /c:"202.96"') do (
for /f %%x in ('echo/%%b %%a') do (
echo %%x
)
)


作者: bing614     时间: 2007-5-4 16:41
楼上的朋友,多谢了,
不过,如果是这样呢.又应该怎么写.
202.96.128.86
192.168.0.254
219.128.3.61

作者: lxmxn     时间: 2007-5-4 16:50
试试这个?
for /f "skip=18 delims=" %%a in ('ipconfig /all') do @echo\%%a

作者: chenall     时间: 2007-5-4 21:01
提供一个思路,
先使用findstr /n /c:"DNS Servers"获取DNS地址所在的行号.
然后再根据行号读取后面的地址.

作者: bing614     时间: 2007-5-5 00:48
多谢chenall给出的提示,已经成功了.代码:
chenall
@echo off&SetLocal ENABLEDELAYEDEXPANSION
SET string=
for /f "tokens=1* delims=:" %%P in ('ipconfig/all^|findstr /n /c:"DNS Servers"') do (
for /f "tokens=* delims=" %%I in ('ipconfig/all^|findstr /n ".*"') do (
for /f "tokens=1* delims=:" %%K in ("%%I") do (
if %%K GEQ %%P (
for /f "tokens=2 delims=: " %%J in ("%%I") do (SET string=!string!;%%J)
)
)
) )

echo ..........
echo !string!>b.txt
pause