1

I want to get the aliases that is returned by nslookup as below:

F:\>nslookup maans20210630125234.sandbox.operations.test.dynamics.com

Server:   UnKnown
Address:  2001:4898::1050:1050
Non-authoritative answer:
Name:    apimgmths6q7kyczcrkpvds6u99ofw4apdrqgxc8s7qavl14wy.cloudapp.net
Address: 52.188.3.251

Aliases:  maans20210630125234.sandbox.operations.test.dynamics.com
          d365-ops-dev-gwy-eastus-eus2-2.azure-api.net
          apimgmttm0hgnv1tmdyrtilrp0hcvphjwrq4gtyzzfdqehnzfn.trafficmanager.net
          d365-ops-dev-gwy-eastus-eus2-2-eastus-01.regional.azure-api.net

nslookup

I want equivalent of above in c sharp. I already tried Dns.GetHostEntry. It does not return aliases as mentioned in official document. How do I get the aliases in C# / .NET?

Dns.GetHostEntry(hostNameOrAddress)

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

1 Answers1

-1

"Aliases" are DNS CNAME records. So you need to find out how to query for DNS CNAME records from your DNS library. You probably need to use a low level DNS library that lets you control all low level details of a DNS query, because high level calls like GetHostEntry are designed to just give you the final answer and hiding the intermediate steps (the CNAME chain resolution).

On the command line the equivalent are:

$ dig maans20210630125234.sandbox.operations.test.dynamics.com +short
d365-ops-dev-gwy-eastus-eus2-2.azure-api.net.
apimgmttm0hgnv1tmdyrtilrp0hcvphjwrq4gtyzzfdqehnzfn.trafficmanager.net.
d365-ops-dev-gwy-eastus-eus2-2-eastus-01.regional.azure-api.net.
apimgmths6q7kyczcrkpvds6u99ofw4apdrqgxc8s7qavl14wy.cloudapp.net.
52.188.3.251

This follows all the intermediate CNAME and gives you the final IP address (as dig does A record type queries by default)

But if you specify record type CNAME you get only the first answer (and hence you will have to do yourself a loop to find out all intermediate CNAME until you get an error or the final answer):

$ dig maans20210630125234.sandbox.operations.test.dynamics.com CNAME +short
d365-ops-dev-gwy-eastus-eus2-2.azure-api.net.
Patrick Mevzek
  • 10,995
  • 16
  • 38
  • 54