How to lookup mx records in dot net core?
Asked Answered
V

2

6

I am trying to port my app across to .net core. It currently uses ArSoft.Tools nuget package to look up mx records but this package is not compatible with core.

What is best way to lookup mx records in core?

Volpe answered 19/9, 2016 at 5:37 Comment(0)
P
11

I ended up creating my own library to do this as there was no other supporting .net-core.

Try DnsClient.NET https://github.com/MichaCo/DnsClient.NET.

Pretty simple to use:

var lookup = new LookupClient();
var result = await lookup.QueryAsync("google.com", QueryType.ANY);

var record = result.Answers.ARecords().FirstOrDefault();
var address = record?.Address;

You can also specify a DNS Server explicitly if you want.

Support for advanced record types or DNSSEC is not done yet though.

Also, maybe one day the .NET library will have support for that, too. I'm working on a API draft. But till then, you have to use some library or write a ton of code ;)

Pharyngeal answered 31/12, 2016 at 1:22 Comment(2)
Thanks, I will try it out when I get time as this will let me port to .net core.Volpe
This saved my day. I was using nslookup check from CMD windows but its not a option in azure :)Kizer
R
6

For a easy universal option, Google provides a DNS-over-HTTP service that automatically handles DNSSEC and returns a simple JSON response to an HTTP GET request.

UI: https://dns.google.com/query?name=google.com&type=MX&dnssec=true

API: https://dns.google.com/resolve?name=google.com&type=MX

{
  "Status": 0,
  "TC": false,
  "RD": true,
  "RA": true,
  "AD": false,
  "CD": false,
  "Question": [
    {
      "name": "google.com.",
      "type": 15
    }
  ],
  "Answer": [
    {
      "name": "google.com.",
      "type": 15,
      "TTL": 536,
      "data": "10 aspmx.l.google.com."
    },
    // ... other answers
  ]
}
Runic answered 12/9, 2017 at 5:50 Comment(1)
Just to add, the google documentation for this is here. The IANA DNS Records referred to are hereSusa

© 2022 - 2024 — McMap. All rights reserved.