Gue*_*lla 3 c# dns mx-record .net-core asp.net-core
我正在尝试将我的应用程序移植到.net核心。当前,它使用ArSoft.Tools nuget包查找mx记录,但是此包与core不兼容。
在核心中查找mx记录的最佳方法是什么?
我最终创建了自己的库来执行此操作,因为没有其他支持.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;
Run Code Online (Sandbox Code Playgroud)
如果需要,还可以显式指定DNS服务器。
但是,尚未支持高级记录类型或DNSSEC。
同样,也许有一天,.NET库也将对此提供支持。我正在研究API草案。但是直到那时,您必须使用一些库或编写大量代码;)
为了提供一个简单的通用选项,Google提供了一种基于HTTP的DNS服务,该服务可自动处理DNSSEC并返回对HTTP GET请求的简单JSON响应。
用户界面: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
  ]
}
Run Code Online (Sandbox Code Playgroud)
        |   归档时间:  |  
           
  |  
        
|   查看次数:  |  
           1340 次  |  
        
|   最近记录:  |