【问题标题】:How to lookup mx records in dot net core?如何在 dot net core 中查找 mx 记录?
【发布时间】:2017-01-26 17:18:50
【问题描述】:

我正在尝试将我的应用程序移植到 .net 核心。它目前使用 ArSoft.Tools nuget 包来查找 mx 记录,但该包与核心不兼容。

在核心中查找 mx 记录的最佳方法是什么?

【问题讨论】:

    标签: c# dns asp.net-core .net-core mx-record


    【解决方案1】:

    我最终创建了自己的库来执行此操作,因为没有其他支持 .net-core。

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

    使用非常简单:

    var lookup = new LookupClient();
    var result = await lookup.QueryAsync("google.com", QueryType.ANY);
    
    var record = result.Answers.ARecords().FirstOrDefault();
    var address = record?.Address;
    

    您也可以根据需要明确指定 DNS 服务器。

    对高级记录类型或 DNSSEC 的支持尚未完成。

    另外,也许有一天 .NET 库也会支持这一点。我正在编写 API 草案。但在那之前,你必须使用一些库或编写大量代码;)

    【讨论】:

    • 谢谢,我会在有时间的时候尝试一下,因为这可以让我移植到 .net 核心。
    • 这拯救了我的一天。我正在使用 CMD windows 中的 nslookup 检查,但它不是 azure 中的选项 :)
    【解决方案2】:

    为了一个简单的通用选项,Google 提供了一个 DNS-over-HTTP 服务,该服务自动处理 DNSSEC 并返回一个简单的 JSON 响应到 HTTP GET 请求。

    用户界面: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
      ]
    }
    

    【讨论】:

    • 只是补充一下,谷歌文档是here。引用的 IANA DNS 记录为 here
    猜你喜欢
    • 2011-05-19
    • 1970-01-01
    • 2011-05-16
    • 1970-01-01
    • 2023-03-14
    • 2010-12-13
    • 2020-09-30
    • 2020-04-20
    • 1970-01-01
    相关资源
    最近更新 更多