如何获得MX记录与System.Net.DNS DNS名称? [英] How to get mx records for a dns name with System.Net.DNS?

查看:326
本文介绍了如何获得MX记录与System.Net.DNS DNS名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有建在.NET库,将返回所有的MX记录给定域的方法?我看你怎么弄CNAMES,但不是MX记录。

Is there any built in method in the .NET library that will return all of the MX records for a given domain? I see how you get CNAMES, but not MX records.

推荐答案

ARSoft.Tools.Net 库赖纳特看来,做这项工作pretty的好。

The ARSoft.Tools.Net library by Alexander Reinert seems to do the job pretty well.

这是从的NuGet:

PM> Install-Package ARSoft.Tools.Net

导入命名空间:

Import the namespace:

using ARSoft.Tools.Net.Dns;

然后做一个同步查找是简单的:

Then making a synchronous lookup is as simple as:

var response = DnsClient.Default.Resolve("gmail.com", RecordType.Mx);
var records = response.AnswerRecords.OfType<MxRecord>();
foreach (var record in records) {
    Console.WriteLine(record.ExchangeDomainName);
}

这给我们的输出:

Which gives us the output:

alt3.gmail-smtp-in.l.google.com
alt4.gmail-smtp-in.l.google.com
gmail-smtp-in.l.google.com
alt1.gmail-smtp-in.l.google.com
alt2.gmail-smtp-in.l.google.com

在底层,它看起来像库构建UDP(或TCP)数据包要发送到解析器,就像你所期望的。图书馆甚至有逻辑(与 DnsClient.Default 调用)来发现要查询的DNS服务器。

Underneath the hood, it looks like the library constructs the UDP (or TCP) packets necessary to send to the resolver, like you might expect. The library even has logic (invoked with DnsClient.Default) to discover which DNS server to query.

完整文档可以在这里找到

Full documentation can be found here.

这篇关于如何获得MX记录与System.Net.DNS DNS名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆