简体   繁体   English

如何在dot net core中查找mx记录?

[英]How to lookup mx records in dot net core?

I am trying to port my app across to .net core. 我正在尝试将我的应用程序移植到.net核心。 It currently uses ArSoft.Tools nuget package to look up mx records but this package is not compatible with core. 它目前使用ArSoft.Tools nuget包来查找mx记录,但是这个包与core不兼容。

What is best way to lookup mx records in core? 在核心中查找mx记录的最佳方法是什么?

I ended up creating my own library to do this as there was no other supporting .net-core. 我最终创建了自己的库来执行此操作,因为没有其他支持.net-core。

Try DnsClient.NET https://github.com/MichaCo/DnsClient.NET . 试试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. 如果需要,还可以显式指定DNS服务器。

Support for advanced record types or DNSSEC is not done yet though. 但是,尚未支持高级记录类型或DNSSEC。

Also, maybe one day the .NET library will have support for that, too. 此外,也许有一天.NET库也会支持它。 I'm working on a API draft. 我正在研究API草案。 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. 为了方便通用选项,Google提供了一种DNS-over-HTTP服务,可自动处理DNSSEC并向HTTP GET请求返回简单的JSON响应。

UI: https://dns.google.com/query?name=google.com&type=MX&dnssec=true 用户界面: https//dns.google.com/query?name = google.com&type = MX&datens = true

API: https://dns.google.com/resolve?name=google.com&type=MX 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
  ]
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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