Ping请求期间发生异常 [英] An exception occurred during a Ping request
问题描述
当我尝试通过主机名ping我的客户端计算机时出现以下错误
-在Ping请求期间发生异常.主机名是:"xyzMicrosoft">
当我尝试通过ipaddress对其客户端计算机执行ping操作时,
I am getting the following error when i am trying to ping my client machine by hostname
--An exception occurred during a Ping request. HostName is : "xyzMicrosoft">
when i try with to ping the client machine by ipaddress its working fine
Dim oPing As New Net.NetworkInformation.Ping
Dim myResponse As Net.NetworkInformation.PingReply
Try
myResponse = oPing.Send(Destination, 5) 'Waits for 5sec to check the given server is online or offline
If myResponse.Status = NetworkInformation.IPStatus.Success Then
Return True
Else
Return False
End If
Catch ex As Exception
logger.Dailylogs(String.Format("PingIPAddress : {0} HostName is : {1} ", ex.Message, Destination))
Return False
End Try
谁能帮忙找出如何使用主机名对计算机执行ping操作
在此先感谢
Bhargav
Can any one help to find out How to ping the machine with Hostname
Thanks in advance
Bhargav
推荐答案
显而易见的问题是:-
1.您得到的例外是什么,有 5个文档 [
另一个观察结果是,超时以毫秒为单位,而不是以秒为单位,因此您只需要等待5毫秒(这对于同一子网中的计算机应该没问题)
The obvious questions are :-
1. What is the exception you get back, there are 5 documented[^]
2. Does ''xyzMicrosoft'' resolve through DNS?
An additional observation, is that the timeout is in milliseconds, not seconds, so you''re only waiting for 5ms (which should be fine for a machine on the same subnet)
做的应该很好,但是尝试在ping中添加更多细节.
What you have done should be fine however try adding a bit more detail to the ping.
Dim options As New PingOptions()
' Use the default Ttl value which is 128,
' but change the fragmentation behavior.
options.DontFragment = True
' Create a buffer of 32 bytes of data to be transmitted.
Dim data As String = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
Dim buffer() As Byte = Encoding.ASCII.GetBytes (data)
Dim timeout As Integer = 120
Dim reply As PingReply = pingSender.Send (args(0), timeout, buffer, options)
这是从 http://msdn.microsoft.com/en-us/library/system.net.networkinformation.ping.aspx [
this was taken from http://msdn.microsoft.com/en-us/library/system.net.networkinformation.ping.aspx[^]
Also in the exception, try catching the PingException first as this may yield more detail about the exception.
这篇关于Ping请求期间发生异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!