'Code by Netpatch
On Error Resume next
Url="http://www.ip138.com/ip2city.asp"
Set NP = Createobject("Microsoft.XMLHTTP") '/创建XMLTTP实例
NP.Open "GET", url, False
NP.Send
Data=NP.responsebody '/获取页面数据
Set NP = Nothing
Data = bytes2BSTR(Data) '/把数据进行转换(防止乱码),为IP地址的定位做铺垫
Here = InstrRev(Data, "您的IP地址是:", -1,0) '/IP位置的大概定位
Data = Mid(Data,Here+8,15) '/以特殊字符串位置为开始向后获取15位
Hers = InstrRev(data, "[",-1,0) '/取得的15位数据中[位置
Data=Mid(Data,Hers+1,15)
Hers = InstrRev(data, "]",-1,0) '/取得的15位数据中]位置
Data=Mid(Data,1,Hers-1)
Set ICEhack = CreateObject("InternetExplorer.Application") '/创建 Inernet Explorer 实例
ICEhack.Navigate("about:blank") '/打开一个空白页
If Hers <> 0 Then '/如果取得的15位数据中存在[
ICEhack.document.parentwindow.clipboardData.SetData "text", Data
Wscript.Echo "已经复制本机外网IP:"&Data&" 到您的剪切板!"
End If
ICEhack.Quit
'Code By N/P
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