![]() |
China DOS Union-- Unite DOS · Advance DOS · Grow DOS --Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum |
| Guest | Log in | Register | Members | Search | China DOS Union |
|
中国DOS联盟论坛 The time now is 2026-08-02 04:42 |
48,037 topics / 350,122 posts / today 2 new / 48,250 members |
| 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`. |
| Printable Version 1,957 / 8 |
| Floor1 zouzhxi | Posted 2006-09-20 11:10 |
| 中级用户 Posts 177 Credits 430 From 广东深圳 | |
|
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. |
|
| Floor2 pengfei | Posted 2006-09-20 11:12 |
| 银牌会员 Posts 485 Credits 1,218 From 湖南.娄底 | |
|
Suggest the LZ to have a look here:
http://www.cn-dos.net/forum/viewthread.php?tid=22392&fpage=2 |
|
| Floor3 zouzhxi | Posted 2006-09-20 22:56 |
| 中级用户 Posts 177 Credits 430 From 广东深圳 | |
|
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. |
|
| Floor4 mountvol | Posted 2006-09-20 23:54 |
| 初级用户 Posts 117 Credits 186 | |
|
```@echo off
for /f "delims=: tokens=2" %%i in ('ipconfig ^| findstr /i /c:"ip address"') do echo %%i >ip.txt ``` |
|
| Floor5 zouzhxi | Posted 2006-09-21 00:44 |
| 中级用户 Posts 177 Credits 430 From 广东深圳 | |
|
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. |
|
| Floor6 electronixtar | Posted 2006-09-21 01:08 |
| 铂金会员 Posts 2,672 Credits 7,493 | |
|
>ip.txt echo fe80 1
|
|
| Floor7 electronixtar | Posted 2006-09-21 01:10 |
| 铂金会员 Posts 2,672 Credits 7,493 | |
|
```
for /f "delims=: tokens=2" %%i in ('ipconfig ^| findstr /i /c:"ip address"') do >ip.txt echo %%i ``` |
|
| Floor8 pengfei | Posted 2006-09-21 01:11 |
| 银牌会员 Posts 485 Credits 1,218 From 湖南.娄底 | |
|
@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 ] |
|
| Floor9 zouzhxi | Posted 2006-09-21 01:36 |
| 中级用户 Posts 177 Credits 430 From 广东深圳 | |
|
Thanks for the answer from floor 8, it's great. I've solved the problem.
|
|
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |