3
votes

Can anyone tell me how to programmatically retrieve the cname and mx records from an internet domain(www.example.com) using c#? According to my short research, I understand it's possible by using UDP socket probe to the DNS server, BUT, is it possible to achieve that without knowing the DNS server address, only the domain name like "www.example.com"? I think it's possible because I've been using some 3rd-party free toolkit to get MX records successfully, without knowing the DNS server address.

Thx a lot

2

2 Answers

1
votes

I haven't tried the libraries mentioned above, but the I would consider using services instead of libraries. I don't know what's the desired use-case, but you can deliver this functionality even on asp.net web application, cross-platform mobile application or mobile website.

  1. Look for online DNS tools (such as DNSWatch), which returns the necessary domain info by URL parameters.
  2. Check the HTML stucture of the result page

You can process this HTML, but Yahoo can do is dirty job for you using YQL html processor and return the relevant part in XML or JSON.

  1. Visit YQL Console
  2. Fill the SQL Statement textarea with the following: select * from html where url="YOUR PARAMETRIC DNS URL" and xpath='XPATH QUERY TO ACCESS NS OR MX RECORD IN THE RESULT HTML'
  3. Test your YQL Statement in the console
  4. Develop a single client application, which executes the YQL statement via HTTP request. You can take hints from this YQL JavaScript tutorial.

Pros: -your application can be very lightweight Cons: -the HTML structure of the result page can be changed or DNSWatch can refuse your request after over-using resources.

Nevertheless you can implement the working prototype in 1 hour.

0
votes

The .Net framework does not support support it directly, but the Platform SDK does MSDN Entry for DnsQuery. All you need to do is import it with DllImport