System.Net.Dns.Resolve issue

  • Thread starter Thread starter Rob Levine
  • Start date Start date
R

Rob Levine

Hi All,

This is a cut down version of a post from earlier entitled "Name resolution
in .Net". Apologies, for the repeat, but I think the first post was too
verbose (it came from a blog article of mine) and I think a shorter post
here is probably more appropriate.

I am seeing some incorrect behaviour on System.Net.Dns.Resolve( hostname )
It would appear that this does more than just a DNS lookup (which is what it
says in the documentation), at least when resolving the address of the
local machine.

I have a server with two NICs and hence two IP addresses: 10.0.0.5 and
192.168.0.2. Only the latter of these has a DNS entry (mapping to the host
name 'terminus'). The former IP address is not listed anywhere (DNS or hosts
file).
If I call System.Net.Dns.Resolve( 'terminus') from the server itself, I get
both IP addresses coming back. How is this possible if the call is only
doing a DNS lookup? A test with nslookup verifies that the name 'terminus'
has a single A record only, pointing to 192.168.0.2.

My suspision is that this call is also checking the NetBIOS name cache;
"netstat -a terminus" lists the same results as the resolve call. If so,
this is not what the documentation says it does.

Any ideas anyone ?
Is it possible to do a DNS lookup ONLY on a hostname ?

Thanks in advance for any help,

Rob Levine
http://roblevine.blogspot.com
 
Rob said:
Hi All,

This is a cut down version of a post from earlier entitled "Name resolution
in .Net". Apologies, for the repeat, but I think the first post was too
verbose (it came from a blog article of mine) and I think a shorter post
here is probably more appropriate.

I am seeing some incorrect behaviour on System.Net.Dns.Resolve( hostname )
It would appear that this does more than just a DNS lookup (which is what it
says in the documentation), at least when resolving the address of the
local machine.

I have a server with two NICs and hence two IP addresses: 10.0.0.5 and
192.168.0.2. Only the latter of these has a DNS entry (mapping to the host
name 'terminus'). The former IP address is not listed anywhere (DNS or hosts
file).
If I call System.Net.Dns.Resolve( 'terminus') from the server itself, I get
both IP addresses coming back. How is this possible if the call is only
doing a DNS lookup? A test with nslookup verifies that the name 'terminus'
has a single A record only, pointing to 192.168.0.2.

My suspision is that this call is also checking the NetBIOS name cache;
"netstat -a terminus" lists the same results as the resolve call. If so,
this is not what the documentation says it does.

Any ideas anyone ?
Is it possible to do a DNS lookup ONLY on a hostname ?

Thanks in advance for any help,

Rob Levine
http://roblevine.blogspot.com

Hi,

maybe no dns lookup is being done at all, as the name matches the one of
the local machine (supposing no two machines can have the same name).
Can you verify that ? What happens if the app is run from another machine ?

Cheers,
Benoit
 
Hi,

maybe no dns lookup is being done at all, as the name matches the one of
the local machine (supposing no two machines can have the same name). Can
you verify that ? What happens if the app is run from another machine ?

Cheers,
Benoit

Hi Benoit,

I suspect you are correct. If I do the same method call from another machine
I only get one IP address back, the one from the DNS.
This leaves me with a problem though; how can I do a DNS lookup for a given
A record for a host (as if I was using something like nslookup) from the
host itself?
There would appear to be no way of doing this within .Net; short of writing
a proper DNS client (or obtaining a 3rd party one).

Any ideas?

It would be helpful if the documentation wasn't so misleading on the nature
of this method call.

Thanks for your hewlp,

Rob
 
Back
Top