获取外网ip地址及物理地址
Private Function GetHTML(sURL) As String
Dim XMLHTTP As Object
Set XMLHTTP = CreateObject("MSXML2.XMLHTTP")
If Not IsObject(XMLHTTP) Then
Set XMLHTTP = CreateObject("Microsoft.XMLHTTP")
If Not IsObject(XMLHTTP) Then Exit Function
End If
XMLHTTP.Open "GET", sURL, True
XMLHTTP.Send
Do While XMLHTTP.ReadyState <> 4
DoEvents
Loop
GetHTML = StrConv(XMLHTTP.ResponseBody, vbUnicode)
End Function
Public Function GetoutIp() As String
Dim txt As String, GetOutIp1 As String, GetOutIp2 As String, startIndex As Integer, endIndex As Integer
txt = GetHTML(" http://www.cz88.net/ip/viewip468.aspx") '去这个网站获取公共的ip地址,即外网ip
GetOutIp1 = Mid(txt, InStr(txt, "IPMessage") + 11, 15)
startIndex = InStr(txt, "AddrMessage") '截取的开始位置
endIndex = InStr(startIndex, txt, "</span>") '截取的结束位置
GetOutIp2 = Mid(txt, startIndex + 13, endIndex - startIndex - 13) 'ip的物理地址
GetoutIp = Left(GetOutIp1, 12) & Format(Val(Mid(GetOutIp1, 13, 3)), "###") & "|" & GetOutIp2
End Function

 

调用:

MsgBox(GetoutIp())