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-06-21 12:20
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Discussion on improving the acquisition of new external network IPs View 1,527 Replies 9
Original Poster Posted 2008-01-07 11:00 ·  中国 湖南 株洲 电信
初级用户
Credits 39
Posts 16
Joined 2006-12-16 08:36
19-year member
UID 73701
Gender Male
Status Offline
The original that the external network IP acquisition was through the swz8.com website extraction
Now this website has been closed. The younger brother found its IP acquisition page from ip138
But I don't know much about text processing. Please help improve it

@echo off
title Get local intranet and external network IP
if exist ip2city.asp del ip2city.asp
if exist ip.txt del ip.txt
if exist 1.txt del 1.txt
if exist 2.txt del 2.txt
wget http://www.ip138.com/ip2city.asp
ren ip2city.asp 1.txt
At this time, the content of 1.txt is


<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<title> Your IP address </title>
</head>
<body style="margin:0px"><center>Your IP address is: From: Zhuzhou City, Hunan Province Telecom</center></body></html>


The following is to extract with SED

sed -r "s/(+\.+\.+\.+).*/\n\1/;s/^.*\n//" 1.txt >2.txt
for /f %%i in (2.txt) do set i=%%i
echo %i% >ip.txt
start ip.txt

The content of IP.txt is

1.1.1.1 space followed by carriage return

I'm a novice. Please help the master to simplify and improve, and remove the space followed by carriage return in IP.TXT
Floor 2 Posted 2008-01-07 11:03 ·  中国 湖南 株洲 电信
初级用户
Credits 39
Posts 16
Joined 2006-12-16 08:36
19-year member
UID 73701
Gender Male
Status Offline
Many codes for removing spaces and line breaks, I tried them, but they didn't work
Floor 3 Posted 2008-01-07 11:18 ·  中国 浙江 杭州 电信
高级用户
★★
Credits 537
Posts 219
Joined 2007-08-04 09:43
18-year member
UID 94620
Gender Male
From 杭州--半山
Status Offline
sed "s/[ |\t]\+$//" ip.txt
Floor 4 Posted 2008-01-07 11:21 ·  中国 湖南 株洲 电信
初级用户
Credits 39
Posts 16
Joined 2006-12-16 08:36
19-year member
UID 73701
Gender Male
Status Offline
Originally posted by junchen2 at 2008-1-7 11:18 AM:
sed "s/\+$//" ip.txt

sed "s/\+$//" ip.txt >1.txt
The space becomes a black block, and the carriage return remains a carriage return
Floor 5 Posted 2008-01-07 11:33 ·  中国 湖南 株洲 电信
初级用户
Credits 39
Posts 16
Joined 2006-12-16 08:36
19-year member
UID 73701
Gender Male
Status Offline
Found a VBS online
But the result is not all numbers

set http=createobject("Microsoft.XMLHTTP")
ipp="http://www.ip138.com/ip2city.asp"
http.open "get",ipp,false
http.send
ss=bytes2BSTR(Http.responsebody)
ss=Replace(ss,vbcrlf,"")
Set re = New RegExp
re.Pattern = "(.+valign=""top"">)(.+\d+\.\d+\.\d+\.\d+)(.+)"
re.Global = True
re.IgnoreCase = True
re.MultiLine = True
rv = re.Replace(ss,"$2")
msgbox rv
Function bytes2BSTR(vIn)
strReturn = ""
For i = 1 To LenB(vIn)
ThisCharCode = AscB(MidB(vIn,i,1))
If ThisCharCode < &H80 Then
strReturn = strReturn & Chr(ThisCharCode)
Else
NextCharCode = AscB(MidB(vIn,i+1,1))
strReturn = strReturn & Chr(CLng(ThisCharCode) * &H100 + CInt(NextCharCode))
i = i + 1
End If
Next
bytes2BSTR = strReturn
End Function
Floor 6 Posted 2008-01-07 12:44 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
19-year member
UID 59080
Status Offline
```batch
for /f "delims= tokens=2" %a in ('wget -qO- http://www.ip138.com/ip2city.asp^|findstr /rc:"\*\]"') do @set/p=my ip is <nul>1.txt
```
Floor 7 Posted 2008-01-07 13:44 ·  中国 广西 玉林 博白县 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
Get IP using VBS:
@echo off
echo Connecting, please wait...
>Getip.vbs echo Set oDOM=WScript.GetObject("http://www.ip138.com/ip2city.asp"):Do Until oDOM.readyState="complete":WScript.sleep 200:Loop:WScript.echo oDOM.documentElement.outerText:Set oDOM=nothing
for /f "tokens=2 delims=" %%i in ('"cscript //nologo Getip.vbs"') do echo Your external network IP is: %%i
del Getip.vbs
pause

The VBS part is ( There must be a WScript.sleep 200 delay part, otherwise it will occupy 99% system resources and not get data for a long time ):
Set oDOM=WScript.GetObject("http://www.ip138.com/ip2city.asp")
Do Until oDOM.readyState="complete"
WScript.sleep 200
Loop
WScript.echo oDOM.documentElement.outerText
Set oDOM=nothing


[ Last edited by zh159 on 2008-1-7 at 01:49 PM ]
Floor 8 Posted 2008-08-29 23:30 ·  中国 新疆 乌鲁木齐 电信
新手上路
Credits 2
Posts 1
Joined 2006-12-18 14:22
19-year member
UID 73870
Gender Male
Status Offline
for /f "skip=6 delims= tokens=2" %%a in ('wget -qO- http://www.ip138.com/ip2city.asp') do set IP=%%a&echo %IP:~0,-2%>IP.txt

Carriage return is not easy to remove...
Floor 9 Posted 2008-12-08 19:06 ·  中国 广东 茂名 电信
初级用户
Credits 42
Posts 23
Joined 2006-02-13 04:23
20-year member
UID 50270
Status Offline
for /f "delims= tokens=2" %%a in ('wget -qO- http://www.ip138.com/ip2city.asp^|findstr /rc:"\*\]"') do @set/p=%%a<nul>1.txt


Pure numbers

The moderator has already given the answer

[ Last edited by pighead123 on 2008-12-8 at 19:16 ]
我是allyesno 帐号忘记密码了 妈的
Floor 10 Posted 2008-12-09 15:19 ·  中国 湖北 武汉 电信
中级用户
★★
Credits 247
Posts 83
Joined 2005-09-12 12:06
20-year member
UID 42446
Gender Male
Status Offline
Mine is like this
curl http://members.3322.org/dyndns/getip
I used to get it on ip138 before, but it was a bit troublesome to analyze the ip.
Forum Jump: