简体   繁体   中英

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?

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
  ]
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM