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-07-02 11:02
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Batch Script for Quickly Obtaining Public Network IP View 2,483 Replies 19
Original Poster Posted 2008-03-30 22:39 ·  中国 浙江 嘉兴 平湖市 电信
初级用户
★★
Credits 157
Posts 67
Joined 2007-05-13 11:03
19-year member
UID 88378
Gender Male
Status Offline
Due to personal needs to obtain the external network IP, the original code method for obtaining from www.ip138.com found online has become invalid. The method provided by the forum takes too long to obtain, which is not very ideal for practical applications. The following is what I wrote when I first learned VBS. It is very fast, but the script is not simplified. I hope experts can help optimize the code.

Working principle of the code:
Download http://www.ip138.com/ip2city.asp, take the 13 characters to the right of "Your IP address is: " and save it to the IP.TXT in the Windows directory. The display method is what I learned from these two lines. Use <to read the content of IP.TXT and display it. Don't laugh at me for being inexperienced. One day I will surpass you. Finally, get %n% which is the value of the external network IP address. This is of great use to me.

As for whether it is original, I think there is no so-called originality. We are not born knowing VBS, but we can call code to work for us, as long as it is practical and effective.

@echo off
echo On Error Resume next >checkip.vbs
echo Url="http://www.ip138.com/ip2city.asp" >>checkip.vbs
echo Set NP = Createobject("Microsoft.XMLHTTP") >>checkip.vbs
echo NP.Open "GET", url, False >>checkip.vbs
echo NP.Send >>checkip.vbs
echo Data=NP.responsebody >>checkip.vbs
echo Set NP = Nothing >>checkip.vbs
echo Data = bytes2BSTR(Data) >>checkip.vbs
echo Here = InstrRev(Data, "您的IP地址是:", -1,0) >>checkip.vbs
echo Data = Mid(Data,Here+9,13) >>checkip.vbs
echo Hers = InstrRev(data, "<",-1,0) >>checkip.vbs
echo Set ICEhack = CreateObject("InternetExplorer.Application") >>checkip.vbs
echo ICEhack.Navigate("about:blank") >>checkip.vbs
echo If Hers ^<^> 0 Then >>checkip.vbs
echo ICEhack.document.parentwindow.clipboardData.SetData "text", Mid(Data,1,Hers-1) >>checkip.vbs
echo Set WshSHell = WScript.CreateObject("WScript.Shell") >>checkip.vbs
echo Set FSO = CreateObject("Scripting.FileSystemObject") >>checkip.vbs
echo Set SCF = FSO.OpenTextFile(FSO.BuildPath(FSO.GetSpecialFolder(0),"ip.txt"),2,True) >>checkip.vbs
echo SCF.Write(Data) >>checkip.vbs
echo SCF.Close >>checkip.vbs
echo Else >>checkip.vbs
echo ICEhack.document.parentwindow.clipboardData.SetData "text", Data >>checkip.vbs
echo Set WshSHell = WScript.CreateObject("WScript.Shell") >>checkip.vbs
echo Set FSO = CreateObject("Scripting.FileSystemObject") >>checkip.vbs
echo Set SCF = FSO.OpenTextFile(FSO.BuildPath(FSO.GetSpecialFolder(0),"ip.txt"),2,True) >>checkip.vbs
echo SCF.Write(Data) >>checkip.vbs
echo SCF.Close >>checkip.vbs
echo End If >>checkip.vbs
echo ICEhack.Quit >>checkip.vbs
echo fso.DeleteFile(WScript.ScriptName) >>checkip.vbs
echo Function bytes2BSTR(vIn) >>checkip.vbs
echo strReturn = "" >>checkip.vbs
echo For i = 1 To LenB(vIn) >>checkip.vbs
echo ThisCharCode = AscB(MidB(vIn,i,1)) >>checkip.vbs
echo If ThisCharCode ^< ^&H80 Then >>checkip.vbs
echo strReturn = strReturn ^& Chr(ThisCharCode) >>checkip.vbs
echo Else >>checkip.vbs
echo NextCharCode = AscB(MidB(vIn,i+1,1)) >>checkip.vbs
echo strReturn = strReturn ^& Chr(CLng(ThisCharCode) * ^&H100 + CInt(NextCharCode)) >>checkip.vbs
echo i = i + 1 >>checkip.vbs
echo End If >>checkip.vbs
echo Next >>checkip.vbs
echo bytes2BSTR = strReturn >>checkip.vbs
echo End Function >>checkip.vbs
checkip.vbs
set/p n=<%windir%\ip.txt&cls
echo External network IP: %n%
pause>nul

[ Last edited by tvzml on 2008-3-30 at 10:57 PM ]
Floor 2 Posted 2008-03-30 22:41 ·  中国 浙江 嘉兴 平湖市 电信
初级用户
★★
Credits 157
Posts 67
Joined 2007-05-13 11:03
19-year member
UID 88378
Gender Male
Status Offline
On Error Resume next
Url="http://www.ip138.com/ip2city.asp"
Set NP = Createobject("Microsoft.XMLHTTP")
NP.Open "GET", url, False
NP.Send
Data=NP.responsebody
Set NP = Nothing
Data = bytes2BSTR(Data)
Here = InstrRev(Data, "您的IP地址是:", -1,0)
Data = Mid(Data,Here+9,13)
Hers = InstrRev(data, "<",-1,0)
Set ICEhack = CreateObject("InternetExplorer.Application")
ICEhack.Navigate("about:blank")
If Hers <> 0 Then
ICEhack.document.parentwindow.clipboardData.SetData "text", Mid(Data,1,Hers-1)
Set WshSHell = WScript.CreateObject("WScript.Shell")
Set FSO = CreateObject("Scripting.FileSystemObject")
Set SCF = FSO.OpenTextFile(FSO.BuildPath(FSO.GetSpecialFolder(0),"ip.txt"),2,True)
SCF.Write(Data)
SCF.Close
Else
ICEhack.document.parentwindow.clipboardData.SetData "text", Data
Set WshSHell = WScript.CreateObject("WScript.Shell")
Set FSO = CreateObject("Scripting.FileSystemObject")
Set SCF = FSO.OpenTextFile(FSO.BuildPath(FSO.GetSpecialFolder(0),"ip.txt"),2,True)
SCF.Write(Data)
SCF.Close
End If
ICEhack.Quit
fso.DeleteFile(WScript.ScriptName)
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 3 Posted 2008-03-31 03:13 ·  中国 四川 成都 教育网
铂金会员
★★★★
Credits 7,493
Posts 2,672
Joined 2005-09-02 00:00
20-year member
UID 42173
Gender Male
Status Offline
The code is really long~~

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'>"
Floor 4 Posted 2008-03-31 13:25 ·  中国 广西 钦州 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
Is it that long?
Set oDOM=WScript.GetObject("http://www.ip138.com/ip2city.asp")
Do Until oDOM.readyState="complete"
WScript.sleep 200
Loop
str = Split(oDOM.documentElement.outerText,"

")
WScript.echo ip(0)
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
fengzi +2 2008-04-03 22:04
Floor 5 Posted 2008-03-31 14:43 ·  中国 浙江 嘉兴 平湖市 电信
初级用户
★★
Credits 157
Posts 67
Joined 2007-05-13 11:03
19-year member
UID 88378
Gender Male
Status Offline
Originally posted by zh159 at 2008-3-31 01:25 PM:
Is it that long?
Set oDOM=WScript.GetObject("http://www.ip138.com/ip2city.asp")
Do Until oDOM.readyState="complete"
WScript.sleep 200
Loop
str = Split(oDOM.document ...



Test succeeded, thank you, learned.
Floor 6 Posted 2008-04-02 12:35 ·  中国 湖南 长沙 电信
初级用户
Credits 25
Posts 16
Joined 2008-04-01 23:43
18-year member
UID 114706
Gender Male
From 湖南
Status Offline
Is there any practical use? Still hope to be pointed out
Floor 7 Posted 2008-04-02 14:34 ·  中国 浙江 嘉兴 平湖市 电信
初级用户
★★
Credits 157
Posts 67
Joined 2007-05-13 11:03
19-year member
UID 88378
Gender Male
Status Offline
The obtained external network IP address can be used in other configuration files.
Floor 8 Posted 2008-04-02 22:09 ·  中国 上海 宝山区 电信
初级用户
Credits 29
Posts 12
Joined 2007-04-17 09:23
19-year member
UID 85486
Gender Male
Status Offline
There are indeed many experts here
Floor 9 Posted 2008-04-03 12:23 ·  中国 河南 安阳 联通
贫困用户
Credits -4
Posts 1
Joined 2008-04-03 11:57
18-year member
UID 114829
Gender Male
Status Offline
Recent Ratings for This Post ( 2 in total) Click for details
RaterScoreTime
pooronce -2 2008-04-03 12:26
fengzi -4 2008-04-03 22:04
Floor 10 Posted 2008-04-03 20:26 ·  中国 陕西 西安 电信
铂金会员
★★★★
Credits 5,212
Posts 2,478
Joined 2007-02-08 23:39
19-year member
UID 79003
Gender Male
Status Offline
Set objrcl = CreateObject("rcbdyctl.Setting")
MsgBox objrcl.GetIPAddress
Set objrcl = Nothing

I don't know how this speed is. Hehe~
Floor 11 Posted 2008-04-03 22:00 ·  中国 陕西 西安 电信
银牌会员
★★★★
钻石会员
Credits 2,278
Posts 1,020
Joined 2007-11-19 13:34
18-year member
UID 103127
Gender Male
Status Offline
When can I be so proficient in using VBS?
山外有山,人外有人;低调做人,努力做事。

进入网盘(各种工具)~~ 空间~~cmd学习
Floor 12 Posted 2008-04-13 22:01 ·  中国 上海 东方有线
初级用户
Credits 40
Posts 17
Joined 2007-08-10 14:49
18-year member
UID 94928
Gender Male
Status Offline
How to automatically upload the obtained address to the FTP space in the form of a file
Floor 13 Posted 2008-04-13 22:54 ·  中国 广西 玉林 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
Originally posted by slore at 2008-4-3 20:26:
Set objrcl = CreateObject("rcbdyctl.Setting")
MsgBox objrcl.GetIPAddress
Set objrcl = Nothing

How about the speed here?~

Dude, please read the question carefully
Floor 14 Posted 2008-04-13 22:56 ·  中国 浙江 嘉兴 平湖市 电信
初级用户
★★
Credits 157
Posts 67
Joined 2007-05-13 11:03
19-year member
UID 88378
Gender Male
Status Offline
Originally posted by lyaa at 2008-4-13 10:01 PM:
How to automatically upload the obtained address to an FTP space as a file.

You can use FTP commands to upload ip.txt.

@echo open 192.168.0.252>ftpcmd
@echo user user pwd>>ftpcmd
@echo prompt>>ftpcmd
@echo binary>>ftpcmd
@echo put ip.txt>>ftpcmd
@echo bye>>ftpcmd
@ftp -n<ftpcmd
Floor 15 Posted 2008-04-14 13:03 ·  中国 陕西 西安 电信
铂金会员
★★★★
Credits 5,212
Posts 2,478
Joined 2007-02-08 23:39
19-year member
UID 79003
Gender Male
Status Offline
Originally posted by zh159 at 2008-4-13 22:54:

Dude, please read the question clearly



I see it clearly...
It is suggested that you test...
Forum Jump: