4

On a machine there might be several IP addresses available. How can I find out all the belonging full qualified domain names (fqdn)?

Update:

I tried the following:

IPHostEntry he = Dns.GetHostEntry(Environment.UserDomainName);
foreach (IPAddress ipAddress in he.AddressList)
{
    string x = ipAddress.ToString();
    string y = Dns.GetHostEntry(ipAddress.ToString()).HostName;
}

I have a machine with 2 IP addresses, the ping using their fqdn returns the correct IPs. However, the code above always return me the one fqdn of the first IP.

My setup looks as follows:

IP1:
123.123.123.123
Name1

IP2:
456.456.456.456
Name2

Both ping and nslookup returns correct value.

The problem is that both rows

Dns.GetHostEntry("123.123.123.123").HostName;
Dns.GetHostEntry("456.456.456.456").HostName;

returns "Name1" (instead of "Name1" and "Name2").

However, the codes

Dns.GetHostEntry("Name1").HostName;
Dns.GetHostEntry("Name2").HostName;

work correctly.

Community
  • 1
  • 1
doab
  • 41
  • 1
  • 3
  • Funny, the computer-name alone is of course the same in both lookups. Maybe you should try telling System.Net to lookup IP2 via a connection over IP2 ? – Stefan Steiger Feb 25 '11 at 11:40

1 Answers1

2

You resolve each IP address to the netbios name.

Dim hostEntry As System.Net.IPHostEntry = System.Net.Dns.GetHostEntry("192.168.115.54")
Console.WriteLine(hostEntry.HostName)

For example if I resolve my IP i get:

PC-MYNAME.MYDOMAIN.local

Then you can also use ActiveDirectory to enumerate the CurrentForrest (available domains).

Stefan Steiger
  • 68,404
  • 63
  • 337
  • 408