检查 Internet 连接 vb.net [英] Check Internet Connection vb.net
本文介绍了检查 Internet 连接 vb.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试运行一些 vb.net 代码来指示我是否已连接到互联网
I am trying to run some vb.net code that indicates if i'm connected to the internet
If My.Computer.Network.IsAvailable Then
MsgBox("Computer is connected.")
Else
MsgBox("Computer is not connected.")
End If
如果我连接到不需要登录的 WiFi 信号,这可以正常工作.如果我连接到需要登录/支付的公共 WiFi 信号,并且在完成此步骤之前执行代码,它仍然告诉我我已连接(理论上是的,但没有支付/登录我不是)
This works fine if I'm connecting to a WiFi signal that doesn't require a login. If I connect to a public WiFi signal that I'm required to login/pay and I execute the code before completing this step it still tells me I'm connected (in theory yes but without paying/logging in I'm not)
任何想法如何设置?
谢谢
推荐答案
您可以通过尝试阅读 Google.com 来检查互联网连接:
You could check for an internet connection by trying to read Google.com:
Public Shared Function CheckForInternetConnection() As Boolean
Try
Using client = New WebClient()
Using stream = client.OpenRead("http://www.google.com")
Return True
End Using
End Using
Catch
Return False
End Try
End Function
取自:此处
这篇关于检查 Internet 连接 vb.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文