十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
Private Sub WebBrowser1_DocumentCompleted(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
成都创新互联公司是专业的淇滨网站建设公司,淇滨接单;提供成都网站建设、成都做网站,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行淇滨网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!
Dim str As String
str = Me.WebBrowser1.Document.Body.InnerHtml
Dim a As Integer = 0
Dim b As Integer = 0
a = InStr(str, "[")
b = InStr(str, "]")
TextBox1.Text = Mid(str, a + 1, b - a - 1)
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.WebBrowser1.Navigate("
)
End Sub
End Class
网页上显示的有点问题,form1_load 中代码是:Me.WebBrowser1.Navigate("")
原理:访问查IP网页后,获取网页上显示的本机外网ip地址
直接对服务器请求。(该服务器要有相对的功能,连线后控件属性即包含,可设置自动回报)
找一个网页,内容含有显示浏览者ip的网址。抓该网页的内容分析获取外网的字串。
提供一个安全网址给你:
是APNIC亚洲数据中心的首页 的子页
vb 如何获取外网ip代码:
'获取公网IP
Private Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" ( _
ByVal sAgent As String, ByVal lAccessType As Long, _
ByVal sProxyName As String, ByVal sProxyBypass As String, _
ByVal lFlags As Long) As Long
Private Declare Function InternetOpenUrl Lib "wininet.dll" Alias "InternetOpenUrlA" ( _
ByVal hInternetSession As Long, ByVal sUrl As String, _
ByVal sHeaders As String, ByVal lHeadersLength As Long, _
ByVal lFlags As Long, ByVal lContext As Long) As Long
Private Declare Function InternetReadFile Lib "wininet.dll" ( _
ByVal hFile As Long, ByVal sBuffer As String, _
ByVal lNumBytesToRead As Long, _
lNumberOfBytesRead As Long) As Integer
Private Declare Function InternetCloseHandle Lib "wininet.dll" ( _
ByVal hInet As Long) As Integer
Private Const INTERNET_FLAG_NO_CACHE_WRITE = H4000000
Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
Public Function GetSub() As String
Dim wburl$, wburl2$, X1, X2, X3, X4
On Error GoTo err
wburl = ""
wburl = GetUrlFile(wburl)
If InStr(1, wburl, "无法找到该页") = 0 Then
X1 = InStr(1, wburl, "[")
X2 = InStr(1, wburl, "]")
X1 = Mid(wburl, X1, X2 - X1)
X1 = Replace(X1, "[", "")
X1 = Replace(X1, " ", "")
X1 = Replace(X1, vbCrLf, "")
GetSub = X1
Exit Function
End If
wburl2 = ""
wburl2 = GetUrlFile(wburl2)
If InStr(1, wburl2, "无法找到该页") = 0 Then
X3 = InStr(1, wburl2, "h2")
X4 = InStr(1, wburl2, "/h2")
X3 = Mid(wburl2, X3, X4 - X3)
X3 = Replace(X3, "h2", "")
X3 = Replace(X3, " ", "")
X3 = Replace(X3, vbCrLf, "")
GetSub = X3
Exit Function
Else
GetSub = "127.0.0.1"
End If
err:
GetSub = "127.0.0.1"
End Function
Private Function GetUrlFile(stUrl As String) As String
Dim lgInternet As Long, lgSession As Long
Dim stBuf As String * 1024
Dim inRes As Integer
Dim lgRet As Long
Dim stTotal As String
stTotal = vbNullString
lgSession = InternetOpen("VBTagEdit", 1, vbNullString, vbNullString, 0)
If lgSession Then
lgInternet = InternetOpenUrl(lgSession, stUrl, vbNullString, _
0, INTERNET_FLAG_NO_CACHE_WRITE, 0)
If lgInternet Then
Do
inRes = InternetReadFile(lgInternet, stBuf, 1024, lgRet)
stTotal = stTotal Mid$(stBuf, 1, lgRet)
Loop While (lgRet 0)
End If
inRes = InternetCloseHandle(lgInternet)
End If
GetUrlFile = stTotal
End Function
使用方法:
在form中调用GetSub就行了。
List1.AddItem ("公网IP:" GetSub + "..")。