Public Function PingaIp(ByVal
endIp As String) As Integer
Dim sRetorno As StringDim lTempoPing As Long
Try
Dim pingSender As New System.Net.NetworkInformation.Ping
Dim opcoes As New System.Net.NetworkInformation.PingOptions
opcoes.DontFragment = True
Dim dados As String = "XXXXXXXXXXXXXXXXXXXXXX"
Dim buffer As Byte() = Encoding.ASCII.GetBytes(dados)
Dim timeout As Integer = 120
Dim resposta As PingReply = pingSender.Send(endIp, timeout, buffer, opcoes)
If resposta.Status = IPStatus.Success Then
lTempoPing = resposta.RoundtripTime + 1
sRetorno = lTempoPing.ToString
Else
sRetorno = "0"
End If
Return CInt(sRetorno)
Catch ex As Exception
Return -1
End Try
End Function
Nenhum comentário:
Postar um comentário