|
tvzml
初级用户
积分 157
发帖 67
注册 2007-5-13
状态 离线
|
『楼 主』:
高速获取公网IP批处理
由于个人需要获取外网IP,在网上找到的获取www.ip138.com原代码方法已经失效,论坛提供的方法获取时间太长,实际应用不太理想,以下是我初学VBS写的,速度非常快,但是脚本没有简化,希望高手帮助优化下代码。
代码工作原理:
下载http://www.ip138.com/ip2city.asp,取“您的IP地址是:" 右13位保存到windows目录下 IP.TXT,显示方法是我这2条到这里学到的,利用<读取IP.TXT内容并显示,大家不要笑我菜,总有一天我会超过你的,最后得到%n% 就是外网IP地址值,这对我来说用途太大了。
至于大家说是不是原创,我认为没有所谓的原创,我们天生下来是不会VBS的,但是我们会调用代码为我们工作,只要实用有效就行了。
@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 外网IP:%n%
pause>nul
[ Last edited by tvzml on 2008-3-30 at 10:57 PM ]
|
|
2008-3-30 22:39 |
|
|
tvzml
初级用户
积分 157
发帖 67
注册 2007-5-13
状态 离线
|
『第
2 楼』:
高速获取公网IP批处理VBS代码
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
|
|
2008-3-30 22:41 |
|
|
electronixtar
铂金会员
积分 7493
发帖 2672
注册 2005-9-2
状态 离线
|
『第
3 楼』:
代码真够长的~~
|
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'>" |
|
2008-3-31 03:13 |
|
|
zh159
金牌会员
积分 3687
发帖 1467
注册 2005-8-8
状态 离线
|
|
2008-3-31 13:25 |
|
|
tvzml
初级用户
积分 157
发帖 67
注册 2007-5-13
状态 离线
|
『第
5 楼』:
Quote: | Originally posted by zh159 at 2008-3-31 01:25 PM:
有这么长么?
[code]Set oDOM=WScript.GetObject("http://www.ip138.com/ip2city.asp")
Do Until oDOM.readyState="complete"
WScript.sleep 200
Loop
str = Split(oDOM.document ... |
|
测试成功,谢谢,学习了。
|
|
2008-3-31 14:43 |
|
|
topmcs
初级用户
积分 25
发帖 16
注册 2008-4-1 来自 湖南
状态 离线
|
|
2008-4-2 12:35 |
|
|
tvzml
初级用户
积分 157
发帖 67
注册 2007-5-13
状态 离线
|
『第
7 楼』:
获取的外网IP地址,可以写其他配置文件用。
|
|
2008-4-2 14:34 |
|
|
1073
初级用户
积分 29
发帖 12
注册 2007-4-17
状态 离线
|
|
2008-4-2 22:09 |
|
|
xiaoweivip
贫困用户
积分 -4
发帖 1
注册 2008-4-3
状态 离线
|
『第
9 楼』:
ddddddddddddddddddd
|
|
2008-4-3 12:23 |
|
|
slore
铂金会员
积分 5212
发帖 2478
注册 2007-2-8
状态 离线
|
『第
10 楼』:
Set objrcl = CreateObject("rcbdyctl.Setting")
MsgBox objrcl.GetIPAddress
Set objrcl = Nothing
不知道这个速度如何嗬~
|
|
2008-4-3 20:26 |
|
|
plp626
银牌会员
钻石会员
积分 2278
发帖 1020
注册 2007-11-19
状态 离线
|
|
2008-4-3 22:00 |
|
|
lyaa
初级用户
积分 40
发帖 17
注册 2007-8-10
状态 离线
|
『第
12 楼』:
怎样再把获得的地址以文件的形势自动上传到ftp空间
|
|
2008-4-13 22:01 |
|
|
zh159
金牌会员
积分 3687
发帖 1467
注册 2005-8-8
状态 离线
|
『第
13 楼』:
Quote: | Originally posted by slore at 2008-4-3 20:26:
Set objrcl = CreateObject("rcbdyctl.Setting")
MsgBox objrcl.GetIPAddress
Set objrcl = Nothing
不知道这个速度如何嗬~ |
|
大哥,看清楚题目
|
|
|
2008-4-13 22:54 |
|
|
tvzml
初级用户
积分 157
发帖 67
注册 2007-5-13
状态 离线
|
『第
14 楼』:
Quote: | Originally posted by lyaa at 2008-4-13 10:01 PM:
怎样再把获得的地址以文件的形势自动上传到ftp空间 |
|
可以使用FTP命令将 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
|
|
2008-4-13 22:56 |
|
|
slore
铂金会员
积分 5212
发帖 2478
注册 2007-2-8
状态 离线
|
『第
15 楼』:
Quote: | Originally posted by zh159 at 2008-4-13 22:54:
大哥,看清楚题目 |
|
看的很清楚……
建议你测试……
|
|
2008-4-14 13:03 |
|