如何检查vb中的Internet连接关闭或活动? [英] How to check If the Internet Connection Down or Active in vb?
本文介绍了如何检查vb中的Internet连接关闭或活动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好
如何检查Internet连接是否可用
How to check If the Internet Connection Available or not
我正在使用Visual Basic 2010
i am using visual basic 2010
可以帮助我
致谢
推荐答案
您可以ping通许多允许ping的网站,以查看您的Internet连接是否正常.下面是一个示例.
You can ping a number of websites that allow pinging to see if your internet connectivity is up. An example follows.
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim Test1 As Integer = 0
Dim Test2 As Integer = 0
Dim Test3 As Integer = 0
Dim Test4 As Integer = 0
If My.Computer.Network.Ping("www.google.com") = True Then
Test1 = 1
ElseIf My.Computer.Network.Ping("www.google.com") = False Then
Test1 = 0
End If
If My.Computer.Network.Ping("www.yahoo.com") = True Then
Test2 = 1
ElseIf My.Computer.Network.Ping("www.yahoo.com") = False Then
Test2 = 0
End If
If My.Computer.Network.Ping("www.bing.com") = True Then
Test3 = 1
ElseIf My.Computer.Network.Ping("www.bing.com") = False Then
Test3 = 0
End If
Test4 = Test1 + Test2 + Test3
If Test4 > 0 Then
MessageBox.Show(Test4 & " ping requests responded to.")
Else
MessageBox.Show("No pings responded to.")
End If
End Sub
End Class
这篇关于如何检查vb中的Internet连接关闭或活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文