本篇介绍怎么在vb.net中ping一个ip或地址
1.Ping IP/Host地址帮助类
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| Imports System.Net.NetworkInformation
Public Class PingHelper
Public Shared Function Ping(host As String, Optional timeout As Integer = 1000) As Boolean Try Dim pg As New Ping Dim pkey As PingReply = pg.Send(host, timeout) If pkey.Status = IPStatus.Success Then Return True End If Return False Catch ex As Exception Return False End Try End Function
End Class
|
2.调用
1
| MessageBox.Show(PingHelper.Ping("baidu.com"))
|