|
zouzhxi
中级用户
   蝴蝶之吻
积分 430
发帖 177
注册 2006-9-20 来自 广东深圳
状态 离线
|
『楼 主』:
DOS下显示IP,并输出到文件,应该怎么写
使用 LLM 解释/回答一下
就是说,,,
我要在DOS下获得本机的IP地址,网关地址,DNS
并将它们在显示的情况下输出到文件中。
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.
|

Butterfly Kiss Blog
计算机DIY联盟论坛 |
|
2006-9-20 11:10 |
|
|
pengfei
银牌会员
    
积分 1218
发帖 485
注册 2006-7-21 来自 湖南.娄底
状态 离线
|
|
2006-9-20 11:12 |
|
|
zouzhxi
中级用户
   蝴蝶之吻
积分 430
发帖 177
注册 2006-9-20 来自 广东深圳
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
我去看了..对我蛮有帮助的.,,,
问题是,出来的效果不是我想要的。
我只想要一个文件,里边只有一个IP。。。如10.10.1.1 简单的一行,就够了。
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.
|
|
2006-9-20 22:56 |
|
|
mountvol
初级用户
 
积分 186
发帖 117
注册 2006-8-14
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
@echo off
for /f "delims=: tokens=2" %%i in ('ipconfig ^| findstr /i /c:"ip address"') do echo %%i >ip.txt
```@echo off
for /f "delims=: tokens=2" %%i in ('ipconfig ^| findstr /i /c:"ip address"') do echo %%i >ip.txt
```
|
|
2006-9-20 23:54 |
|
|
zouzhxi
中级用户
   蝴蝶之吻
积分 430
发帖 177
注册 2006-9-20 来自 广东深圳
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
也不行。。。只能输出一个
echo 10.10.1.1
echo fe80 1>ip.txt
echo fe80 1>ip.txt
echo fe80 1>ip.txt
出来的是fe80呀。。。并没有把10.10.1.1写进去了。
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.
|
|
2006-9-21 00:44 |
|
|
electronixtar
铂金会员
      
积分 7493
发帖 2672
注册 2005-9-2
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
>ip.txt echo fe80 1
>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'>" |
|
2006-9-21 01:08 |
|
|
electronixtar
铂金会员
      
积分 7493
发帖 2672
注册 2005-9-2
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
for /f "delims=: tokens=2" %%i in ('ipconfig ^| findstr /i /c:"ip address"') do >ip.txt echo %%i
```
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'>" |
|
2006-9-21 01:10 |
|
|
pengfei
银牌会员
    
积分 1218
发帖 485
注册 2006-7-21 来自 湖南.娄底
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
@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 外网IP=%IP%
echo.
echo 网关=%Gateway%
echo.
echo DNS=%DNS%
)>ip.txt
楼主只需要修改下面三个值, 便能得到内外网的IP和网关:
if "!IP_num!"=="2"
if "!Gateway_num!"=="0"
if "!DNS_num!"=="0"
后面的跟的值不同提取到的IP也不同,请自行测试!
另外DNS只提取了第一个, 符合楼主的要求吗?
Last edited by pengfei on 2006-9-21 at 23:47 ]
@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 ]
|

业精于勤而荒于嬉,形成于思而毁于随。 |
|
2006-9-21 01:11 |
|
|
zouzhxi
中级用户
   蝴蝶之吻
积分 430
发帖 177
注册 2006-9-20 来自 广东深圳
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
谢谢8楼的回答,棒极了。。吾该晒呢。。。我已经解决了问题
Thanks for the answer from floor 8, it's great. I've solved the problem.
|
|
2006-9-21 01:36 |
|