Click here to Skip to main content
15,920,111 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

VB
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


Can any one help to find out How to ping the machine with Hostname

Thanks in advance
Bhargav
Posted
Updated 13-Jun-12 23:10pm
v2

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)
 
Share this answer
 
Comments
Bhargav1985 14-Jun-12 5:35am    
PingException
barneyman 14-Jun-12 5:57am    
You are catching a generic exception, that API hands 5 different exceptions back, handle them all - documentation on how in VB is here
barneyman 14-Jun-12 6:38am    
Catch the PingException, get the message from that, examine the InnerException if there is one, and get it's message - all the clues are in the documentation, take time to RTFM
What you have done should be fine however try adding a bit more detail to the ping.

VB
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)


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.
 
Share this answer
 
Comments
Bhargav1985 14-Jun-12 6:12am    
Same Problem...No use
Member 11227213 23-May-16 9:05am    
Hi Bhargav1985
Reference your post "Exception occurred during a Ping request" -- dated 13th June 2012. Did you ever find a resolution?
I have a very similar problem.
Best Wishes
Keith, UK

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900