Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to lookup mx records in dot net core?

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?

like image 868
Guerrilla Avatar asked Sep 19 '16 05:09

Guerrilla


People also ask

What is MX DNS lookup?

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.

What does MX lookup do?

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).


Video Answer


2 Answers

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 ;)

like image 188
MichaC Avatar answered Oct 18 '22 00:10

MichaC


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
  ]
}
like image 24
Mani Gandham Avatar answered Oct 17 '22 22:10

Mani Gandham