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-02 03:36
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » To display the IP under DOS and output it to a file, you can use the following steps: First, use the `ipconfig` command to get the IP information. Then, redirect the output to a file. The typical command would be: ```batch ipconfig | findstr "IPv4 Address" > ip.txt ``` This command runs the `ipconfig` command, pipes its output to `findstr` to filter out the line containing "IPv4 Address", and then redirects the result to a file named `ip.txt`. View 1,956 Replies 8
Original Poster Posted 2006-09-20 11:10 ·  IANA 局域网IP(Private-Use)
中级用户
★★
蝴蝶之吻
Credits 430
Posts 177
Joined 2006-09-20 12:00
19-year member
UID 63170
From 广东深圳
Status Offline
I mean,,,

I need to obtain the local machine's IP address, gateway address, and DNS under DOS, and output them to a file while displaying them.
Floor 2 Posted 2006-09-20 11:12 ·  中国 湖南 娄底 新化县 电信
银牌会员
★★★
Credits 1,218
Posts 485
Joined 2006-07-21 21:24
20-year member
UID 58987
From 湖南.娄底
Status Offline
业精于勤而荒于嬉,形成于思而毁于随。
Floor 3 Posted 2006-09-20 22:56 ·  IANA 局域网IP(Private-Use)
中级用户
★★
蝴蝶之吻
Credits 430
Posts 177
Joined 2006-09-20 12:00
19-year member
UID 63170
From 广东深圳
Status Offline
I went to take a look.. It was quite helpful to me....
The problem is that the resulting effect isn't what I wanted.

I just want a single file with only one IP.. like 10.10.1.1, just a simple single line, that's enough.
Floor 4 Posted 2006-09-20 23:54 ·  中国 湖北 荆门 电信
初级用户
★★
Credits 186
Posts 117
Joined 2006-08-14 14:50
19-year member
UID 60491
Status Offline
```@echo off
for /f "delims=: tokens=2" %%i in ('ipconfig ^| findstr /i /c:"ip address"') do echo %%i >ip.txt
```
Floor 5 Posted 2006-09-21 00:44 ·  IANA 局域网IP(Private-Use)
中级用户
★★
蝴蝶之吻
Credits 430
Posts 177
Joined 2006-09-20 12:00
19-year member
UID 63170
From 广东深圳
Status Offline
It doesn't work either... Only one is output.
echo 10.10.1.1
echo fe80 1>ip.txt
echo fe80 1>ip.txt
echo fe80 1>ip.txt
What comes out is fe80... The 10.10.1.1 is not written in.
Floor 6 Posted 2006-09-21 01:08 ·  中国 广东 深圳 盐田区 教育网
铂金会员
★★★★
Credits 7,493
Posts 2,672
Joined 2005-09-02 00:00
20-year member
UID 42173
Gender Male
Status Offline
>ip.txt echo fe80 1

C:\>BLOG http://initiative.yo2.cn/
C:\>hh.exe ntcmds.chm::/ntcmds.htm
C:\>cmd /cstart /MIN "" iexplore "about:<bgsound src='res://%ProgramFiles%\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll/10/5432'>"
Floor 7 Posted 2006-09-21 01:10 ·  中国 四川 成都 教育网
铂金会员
★★★★
Credits 7,493
Posts 2,672
Joined 2005-09-02 00:00
20-year member
UID 42173
Gender Male
Status Offline
```
for /f "delims=: tokens=2" %%i in ('ipconfig ^| findstr /i /c:"ip address"') do >ip.txt echo %%i
```

C:\>BLOG http://initiative.yo2.cn/
C:\>hh.exe ntcmds.chm::/ntcmds.htm
C:\>cmd /cstart /MIN "" iexplore "about:<bgsound src='res://%ProgramFiles%\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll/10/5432'>"
Floor 8 Posted 2006-09-21 01:11 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 1,218
Posts 485
Joined 2006-07-21 21:24
20-year member
UID 58987
From 湖南.娄底
Status Offline
@echo off
setlocal enabledelayedexpansion
set IP_num=0
set Gateway_num=0
set DNS_num=0
for /f "tokens=2* delims=:" %%i in ('ipconfig /all ^| find /i "IP Address"') do (
for /f "tokens=2* delims=:" %%a in ('ipconfig /all ^| find /i "Default Gateway"') do (
for /f "tokens=2* delims=:" %%1 in ('ipconfig /all ^| find /i "DNS Servers"') do (
set IP_=%%i
set Gateway_=%%a
set DNS_=%%1
if "!IP_num!"=="2" set IP=!IP_:~1!
if "!Gateway_num!"=="0" set Gateway=!Gateway_:~1!
if "!DNS_num!"=="0" set DNS=!DNS_:~1!
set /a IP_num=!IP_num!+1
set /a Gateway_num=!Gateway_num!+1
set /a DNS_num=!DNS_num!+1
)
)
)
(echo External network IP=%IP%
echo.
echo Gateway=%Gateway%
echo.
echo DNS=%DNS%
)>ip.txt

The owner only needs to modify the following three values to get the internal and external network IPs and gateways:
if "!IP_num!"=="2"
if "!Gateway_num!"=="0"
if "!DNS_num!"=="0"
The values following are different, and the extracted IPs are different. Please test by yourself!

In addition, only the first DNS is extracted. Does it meet the owner's requirements?

[ Last edited by pengfei on 2006-9-21 at 23:47 ]
业精于勤而荒于嬉,形成于思而毁于随。
Floor 9 Posted 2006-09-21 01:36 ·  IANA 局域网IP(Private-Use)
中级用户
★★
蝴蝶之吻
Credits 430
Posts 177
Joined 2006-09-20 12:00
19-year member
UID 63170
From 广东深圳
Status Offline
Thanks for the answer from floor 8, it's great. I've solved the problem.
Forum Jump: