go编程之DNS查询

本文介绍了如何使用Go(golang)进行DNS查询A记录,讲解了安装DNS包并使用Exchange函数获取A记录的过程。同时,文章还探讨了枚举子域名的方法,通过向DNS服务器发送请求来猜测子域名。
摘要由CSDN通过智能技术生成

DNS查询A记录

首先需要安装go dns包

go get github.com/mikg/dns
type Msg struct {
        MsgHdr
        Compress bool       `json:"-"` // If true, the message will be compressed when converted to wire format.
        Question []Question // Holds the RR(s) of the question section.
        Answer   []RR       // Holds the RR(s) of the answer section.
        Ns       []RR       // Holds the RR(s) of the authority section.
        Extra    []RR       // Holds the RR(s) of the additional section.
}

 Exchange函数的返回值为Msg,结构体如上.

创建一个Msg,向DNS服务器发送需要查询的网址以及设置要查询的类型为A记录.获取Exchange返回的结构体,查询其中的Answer内容.

代码如下:

package main

import (
	"fmt"
	"github.com/miekg/dns"
)

func main() {
	var msg dns.Msg                             //创建一个Msg
	fqdn := dns.Fqdn("stacktitan.com")          //调用fqdn将域转换为可以与DNS服务交换的FQDN
	msg.SetQuestion(fqdn, dns.TypeA)            
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

m0_48984604

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值