China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-04 11:10
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Question for batch experts: a DOS batch file problem ●●●●●●●● View 877 Replies 5
Original Poster Posted 2007-04-26 03:54 ·  中国 河南 郑州 联通
新手上路
Credits 6
Posts 2
Joined 2007-04-23 05:43
19-year member
UID 86160
Gender Male
Status Offline
Question for batch experts: a DOS batch file problem ●●●●●●●●

I want to run a batch file on a schedule. When I run ipconfig, it looks like this:
Windows IP Configuration


Ethernet adapter Wireless Network Connection:

Connection-specific DNS Suffix . :
IP Address. . . . . . . . . . . . : 218.29.153.103
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 218.29.153.254


I only want to output 218.29.153.103 into the text file ipconfig.txt and save it as a log!
What should I do?
Because the IP is assigned by DHCP, the line with 218.29.153.103 sometimes changes (because sometimes it disconnects and then reconnects).


The ideal effect for the ipconfig.txt log would be like this:
218.29.153.103
218.29.153.122
218.29.153.4
218.29.153.55
.
.
.
Please help, experts!
Floor 2 Posted 2007-04-26 04:32 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline
Floor 3 Posted 2007-04-26 08:56 ·  中国 河南 郑州 联通
新手上路
Credits 6
Posts 2
Joined 2007-04-23 05:43
19-year member
UID 86160
Gender Male
Status Offline
Originally posted by lxmxn at 2007-4-25 03:32 PM:
for /f "tokens=2 delims=:" %%a in ('ipconfig^|find /i "ip address"') do echo/%%a>>ipconfig.txt

Moderator, thanks! Awesome!
Floor 4 Posted 2007-04-26 10:03 ·  中国 江苏 苏州 电信
中级用户
★★
我是DOS学者
Credits 367
Posts 180
Joined 2006-05-14 10:53
20-year member
UID 55507
Gender Male
From 重庆
Status Offline
There's one thing I don't understand about for: what exactly does tokens=2 mean? If it means the 2nd line, I just can't make sense of it no matter how I think about it...
Floor 5 Posted 2007-04-26 10:30 ·  中国 河南 开封 教育网
中级用户
Credits 204
Posts 44
Joined 2003-08-08 00:00
22-year member
UID 8224
Gender Male
Status Offline
OP, please write your title properly and make it clear it's DOS batch. I came in and found it's actually CMD, what a mess.
Floor 6 Posted 2007-04-26 11:16 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline
Originally posted by BWSkyer at 2007-4-25 21:03:
There's one thing I don't understand about for: what exactly does tokens=2 mean? If it means the 2nd line, I just can't make sense of it no matter how I think about it...

tokens=2 means the second column. You can search the forum for posts about how to use the for command.
Forum Jump: