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联盟论坛 » 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
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.
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?