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?
The MX Record Lookup tool is an online tool that lets you query DNS servers and get instant results. Mail Exchanger or MX lookups are used to determine the MX records associated with a domain.
A DNS 'mail exchange' (MX) record directs email to a mail server. The MX record indicates how email messages should be routed in accordance with the Simple Mail Transfer Protocol (SMTP, the standard protocol for all email).
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 ;)
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
]
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With