获取 DNS 记录的 ttl 值

发布于 2024-08-14 12:21:30 字数 76 浏览 4 评论 0原文

我正在编写一个程序来收集各种 DNS 记录的 ttl 数据。我可以为 SOA 获取它。谁能告诉我如何获取 MX、A 记录的 ttl 值吗?

Iam writing a program to gather data on ttl of various DNS records.I could get it for SOA. Can anyone say how to obtain ttl value for MX , A records ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

下壹個目標 2024-08-21 12:21:30

编辑:您必须在 DNS 中查询 MX 或 A 记录

您的完整响应应包含:

  1. DNS 标头部分
  2. 问题部分,其中各部分将发送回给您(问题编号可在 dns 标头中找到)。
  3. 答案部分,可以在其中找到答案(与问题部分类似,答案的数量也可以在 dns 标头中找到)

现在,每个答案将有自己的标头,其形式如下:

type     - 16 bits
class    - 16 bits
ttl      - 32 bits
rdlength - 16 bits

后面的内容标头取决于响应的类型,但 ttl 位于标头中。

以下是一些参考:http://www.ietf.org/rfc/rfc1035.txt

Edit: You'll have to query the DNS for MX or A records

Your complete response should contain:

  1. a DNS header section
  2. a question section in which the sections are sent back to you (the questions number is found in the dns header).
  3. an answer section in which the answers will be found (similar to the question section, the number of the answers can also be found in the dns header)

Now, each answer will have its own header, that has the following form:

type     - 16 bits
class    - 16 bits
ttl      - 32 bits
rdlength - 16 bits

the content after the header depends on the type of response, but the ttl is in the header.

Here's some reference: http://www.ietf.org/rfc/rfc1035.txt

两人的回忆 2024-08-21 12:21:30

如果您使用 .NET,那么 CodeProject 上有一个相当不错的 DNS 库。

您应该能够像这样使用它:

IPAddress dnsServerAddress = IPAddress.Parse("208.67.222.222");

Request request = new Request();
request.AddQuestion(new Question("microsoft.com", DnsType.ANAME, DnsClass.IN));

Response response = Resolver.Lookup(request, dnsServerAddress);

foreach (Answer answer in response.Answers)
{
    Console.WriteLine("{0}: ttl {1}", 
        ((ANameRecord)answer.Record).IPAddress, answer.Ttl);
}

If you're working in .NET, there is a fairly good DNS library on CodeProject.

You should be able to use it like this:

IPAddress dnsServerAddress = IPAddress.Parse("208.67.222.222");

Request request = new Request();
request.AddQuestion(new Question("microsoft.com", DnsType.ANAME, DnsClass.IN));

Response response = Resolver.Lookup(request, dnsServerAddress);

foreach (Answer answer in response.Answers)
{
    Console.WriteLine("{0}: ttl {1}", 
        ((ANameRecord)answer.Record).IPAddress, answer.Ttl);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文