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-07 20:38
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Urgent!!! Batch processing to view local IP and external network IP View 1,881 Replies 7
Original Poster Posted 2008-03-18 14:23 ·  中国 广东 广州 电信
初级用户
★★
Credits 131
Posts 119
Joined 2007-06-12 22:50
19-year member
UID 91125
Gender Male
From gz
Status Offline
Urgent!!! Batch processing to view local IP and external network IP

Question: Can batch processing be used to check the external network IP? (The local IP is: 192.168.1.2~254, which is the internal network here)
Floor 2 Posted 2008-03-18 14:35 ·  中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
Credits 3,105
Posts 1,276
Joined 2008-03-08 13:00
18-year member
UID 112398
Gender Male
Status Offline
Yes, but I don't know which external network you want to view. Is it the external network IP of the LAN server host?
Floor 3 Posted 2008-03-18 14:43 ·  中国 广东 广州 电信
高级用户
★★★
潜水修练批处理
Credits 788
Posts 366
Joined 2006-12-31 02:43
19-year member
UID 75048
Gender Male
Status Offline
External network IP

Use wget.exe (http://www.yx127.com/tools/wget_1.82.rar)


@echo off
del ips.asp 1>nul 2>&1
wget http://www.ip138.com/ips.asp 1>nul 2>&1
for /f "tokens=2 skip=2 delims=" %%i in ('find "Your IP address is:" ips.asp') do echo %%i
del ips.asp 1>nul 2>&1
pause
正在潜水修练的批处理小白
Floor 4 Posted 2008-03-18 14:47 ·  中国 广东 广州 电信
初级用户
★★
Credits 131
Posts 119
Joined 2007-06-12 22:50
19-year member
UID 91125
Gender Male
From gz
Status Offline
Still need to download files? I made one.

@echo off
echo Set objXML = WScript.GetObject("http://www.apnic.net/")

>>apnic.vbs
echo While objXML.readyState = "loading">>apnic.vbs
echo WScript.Sleep 100>>apnic.vbs
echo Wend>>apnic.vbs
echo Set coll = objXML.getElementsByTagName("td")>>apnic.vbs
echo WScript.Echo coll(0).innertext>>apnic.vbs
echo Set objXML = Nothing>>apnic.vbs
for /f "delims=: tokens=2" %%i in ('cscript //nologo apnic.vbs') do

set "wip=%%i"
echo 本机外网IP是 %wip%>>ip.txt
del apnic.vbs /q
Floor 5 Posted 2008-03-18 14:57 ·  中国 广东 广州 电信
高级用户
★★★
潜水修练批处理
Credits 788
Posts 366
Joined 2006-12-31 02:43
19-year member
UID 75048
Gender Male
Status Offline
One of the differences between VBS and batch processing:
Batch processing does not have a built-in download command;
In the case of pure batch processing, it is to use wget.

P.S. The above has a grammar error (It seems there was an issue with line breaks during copy - paste), modified as follows:

@echo off
echo Set objXML = WScript.GetObject("http://www.apnic.net/")>apnic.vbs
echo While objXML.readyState = "loading">>apnic.vbs
echo WScript.Sleep 100>>apnic.vbs
echo Wend>>apnic.vbs
echo Set coll = objXML.getElementsByTagName("td")>>apnic.vbs
echo WScript.Echo coll(0).innertext>>apnic.vbs
echo Set objXML = Nothing>>apnic.vbs
for /f "delims=: tokens=2" in ('cscript //nologo apnic.vbs') do echo 本机外网IP是 %%i>ip.txt
del apnic.vbs /q


[ Last edited by dikex on 2008 - 3 - 18 at 03:01 PM ]
正在潜水修练的批处理小白
Floor 6 Posted 2008-03-18 14:58 ·  中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
Credits 3,105
Posts 1,276
Joined 2008-03-08 13:00
18-year member
UID 112398
Gender Male
Status Offline
I think it's better to use tracert:
tracert www.baidu.com
pause
In the subsequent list of IPs, the first non-local area network IP from top to bottom is the external network IP of the local area network. As for whether it's necessary to list it separately, it's probably not necessary.
Floor 7 Posted 2008-03-18 15:01 ·  中国 广东 广州 电信
高级用户
★★★
潜水修练批处理
Credits 788
Posts 366
Joined 2006-12-31 02:43
19-year member
UID 75048
Gender Male
Status Offline
I think tracert is sometimes strange:

Now my IP is 59.41.32.*

But the result of tracert www.baidu.com is:

Tracing route to www.a.shifen.com
over a maximum of 30 hops:

1 43 ms 42 ms 43 ms 220.181.37.55

Trace complete.
正在潜水修练的批处理小白
Floor 8 Posted 2008-03-18 16:17 ·  中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
Credits 3,105
Posts 1,276
Joined 2008-03-08 13:00
18-year member
UID 112398
Gender Male
Status Offline
```
@echo off
for /f "delims=: tokens=2" %%i in ('ipconfig/all ^| find "DNS"') do set dns=%%i
for /f "skip=6 tokens=8" %%i in ('tracert %dns%') do set ip=%%i
echo %ip%

注:在我这里(xp+sp2环境)skip=6,不知道你那里是要设为5还是6?
也可以这样:
@echo off
for /f "skip=6 tokens=8" %%i in ('tracert %dns%') do (
for /f "delims=: tokens=2" %%i in ('ipconfig/all ^| find "DNS"') do (
set dns=%%i
)
set ip=%%i
)
echo %ip%

[ Last edited by zw19750516 on 2008-3-18 at 05:33 PM ]
```
Forum Jump: