VB.NET网络是否联通Function

时间:2022-08-26 22:34:55

''' <summary>
    ''' IP Ping
    ''' </summary>
    ''' <param name="strIpOrDName">IP地址</param>
    ''' <returns>是否成功</returns>
    ''' <remarks></remarks>
    Private Function PingIpOrDomainName(ByVal strIpOrDName As String) As Boolean
        Dim objPingSender As New Ping
        Dim objPinOptions As New PingOptions()
        objPinOptions.DontFragment = True
        Dim data As String = theData
        Dim buffer() As Byte = Encoding.UTF8.GetBytes(data)
        Dim intTimeout As Integer = 120
        Dim objPinReply As PingReply = objPingSender.Send(strIpOrDName, intTimeout, buffer, objPinOptions)
        Dim strInfo As String = objPinReply.Status.ToString()
        If strInfo = "Success" Then
            Return True
        End If
        Return False
    End Function