GetHostByName Nightmares

  • Thread starter Thread starter Alex Sinclair
  • Start date Start date
A

Alex Sinclair

Hi,

I'm trying to get the ip address of a website given its hostname. I'm
using the System.Net.Dns.GetHostByName(<hostname>)
using C# and ASP.NET.

This is not working reliably at all: for example. www.yahoo.com works just
fine, returning back the IP address, on the other hand, Google, MS, Sun, and
numerous others just return a Socket Exception:

"The requested name is valid and was found in the database, but it does not
have the correct associated data being resolved for"

Is there any other way to get the IP address of a website in a reliable
manner? why does this work using ping or tracert but doesn't work in
ASP.NET? (haven't checked using the Win32 API lately, but I have the feeling
it would work just fine).

Thanks,

Alex
 
Generally it means - The DNS is not properly configured on the workstation
or there are problems with the DNS server.
Check the list of Dns Servers in ur network configuration.

You can also try Dns.Resolve.
 
sorry .. little err ... Resolve internally uses
GetHostByName/GetHostByAddress ... problem seems to be with ur DNS config or
the Dns server ... I can easily resolve all those google/msn etc here..
 
Hi, and thanks for the reply. I moved the code to a web host (as opposed to
localhost), well, now I'm getting a different error, which I understand
means a similar thing (that there is no address associated with the name).
Here's the Socket exception I'm now getting when calling GetHostName:

The requested name is valid, but no data of the requested type was found

Thanks,

Alex
 
Last edited:
Back
Top