How to get fqdn ip addresses in c #?

Multiple IP addresses may be available on the computer. How to find out all your fully 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 two IP addresses, ping, using their fqdn, returns the correct IP addresses. However, the code above always returns me one fqdn of the first IP.

My setup is as follows:

IP1:
123.123.123.123
Name1

IP2:
456.456.456.456
Name2

Both ping and nslookup return the correct value.

The problem is that both lines

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

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

However codes

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

work correctly.

+4
source share
1 answer

You resolve each netbios IP address.

 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 address, I get:

 PC-MYNAME.MYDOMAIN.local 

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

+2
source

Source: https://habr.com/ru/post/1341121/


All Articles