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 = stTotalMid$(stBuf, 1, lgRet)
Loop While (lgRet0)
End If
inRes = InternetCloseHandle(lgInternet)
End If
GetUrlFile = stTotal
End Function
使用方法:
在form中调用GetSub就行了 。
List1.AddItem ("公网IP:"GetSub + "..") 。
VB2013,VB.net 外网IP获取问题!直接对服务器请求 。(该服务器要有相对的功能,连线后控件属性即包含,可设置自动回报)
找一个网页,内容含有显示浏览者ip的网址 。抓该网页的内容分析获取外网的字串 。
提供一个安全网址给你:
是APNIC亚洲数据中心的首页的子页
VB.net 2015 如何获取外网IP并保存到软件目录下的IP.txt文件Private Sub WebBrowser1_DocumentCompleted(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
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地址
vb.net外网ip的介绍就聊到这里吧,感谢你花时间阅读本站内容 , 更多关于vbnet http服务器、vb.net外网ip的信息别忘了在本站进行查找喔 。
推荐阅读
- 投资教程直播,投资课视频
- vs2017打包程序指定net,vs 打包
- 云梦网站制作,云梦吧网站管理系统
- 硬盘上的颗粒怎么买到,硬盘 颗粒
- 命令行怎么删除mysql表 命令删除mysql服务
- oracle数据库的备份和恢复命令,oracle数据库备份恢复
- 监视动作指令游戏,监视软件动作
- 如何搞好电商服务,如何开展电商业务
- python饼图函数教程 python画饼图