• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang dns.A类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/miekg/dns.A的典型用法代码示例。如果您正苦于以下问题:Golang A类的具体用法?Golang A怎么用?Golang A使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了A类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: handleIPQuery

func (r *resolver) handleIPQuery(name string, query *dns.Msg, ipType int) (*dns.Msg, error) {
	addr, ipv6Miss := r.sb.ResolveName(name, ipType)
	if addr == nil && ipv6Miss {
		// Send a reply without any Answer sections
		log.Debugf("Lookup name %s present without IPv6 address", name)
		resp := createRespMsg(query)
		return resp, nil
	}
	if addr == nil {
		return nil, nil
	}

	log.Debugf("Lookup for %s: IP %v", name, addr)

	resp := createRespMsg(query)
	if len(addr) > 1 {
		addr = shuffleAddr(addr)
	}
	if ipType == types.IPv4 {
		for _, ip := range addr {
			rr := new(dns.A)
			rr.Hdr = dns.RR_Header{Name: name, Rrtype: dns.TypeA, Class: dns.ClassINET, Ttl: respTTL}
			rr.A = ip
			resp.Answer = append(resp.Answer, rr)
		}
	} else {
		for _, ip := range addr {
			rr := new(dns.AAAA)
			rr.Hdr = dns.RR_Header{Name: name, Rrtype: dns.TypeAAAA, Class: dns.ClassINET, Ttl: respTTL}
			rr.AAAA = ip
			resp.Answer = append(resp.Answer, rr)
		}
	}
	return resp, nil
}
开发者ID:CWSpear,项目名称:docker,代码行数:35,代码来源:resolver.go


示例2: handleSRVQuery

func (r *resolver) handleSRVQuery(svc string, query *dns.Msg) (*dns.Msg, error) {

	srv, ip := r.backend.ResolveService(svc)

	if len(srv) == 0 {
		return nil, nil
	}
	if len(srv) != len(ip) {
		return nil, fmt.Errorf("invalid reply for SRV query %s", svc)
	}

	resp := createRespMsg(query)

	for i, r := range srv {
		rr := new(dns.SRV)
		rr.Hdr = dns.RR_Header{Name: svc, Rrtype: dns.TypePTR, Class: dns.ClassINET, Ttl: respTTL}
		rr.Port = r.Port
		rr.Target = r.Target
		resp.Answer = append(resp.Answer, rr)

		rr1 := new(dns.A)
		rr1.Hdr = dns.RR_Header{Name: r.Target, Rrtype: dns.TypeA, Class: dns.ClassINET, Ttl: respTTL}
		rr1.A = ip[i]
		resp.Extra = append(resp.Extra, rr1)
	}
	return resp, nil

}
开发者ID:jwhonce,项目名称:docker,代码行数:28,代码来源:resolver.go


示例3: handleARequest

func (s *DNSServer) handleARequest(r *dns.Msg, m *dns.Msg) {
	m.Answer = make([]dns.RR, 0, 2)
	query := r.Question[0].Name

	if query[len(query)-1] == '.' {
		query = query[:len(query)-1]
	}

	for service := range s.queryServices(query) {
		rr := new(dns.A)

		var ttl int
		if service.Ttl != -1 {
			ttl = service.Ttl
		} else {
			ttl = s.config.ttl
		}

		rr.Hdr = dns.RR_Header{
			Name:   r.Question[0].Name,
			Rrtype: dns.TypeA,
			Class:  dns.ClassINET,
			Ttl:    uint32(ttl),
		}
		rr.A = service.Ip
		m.Answer = append(m.Answer, rr)
	}
}
开发者ID:jverdeyen-forks,项目名称:dnsdock,代码行数:28,代码来源:dnsserver.go


示例4: GenerateServeDNS

func (c *Config) GenerateServeDNS(hostname string) func(dns.ResponseWriter, *dns.Msg) {
	if len(hostname) > 0 {
		if hostname[len(hostname)-1] != '.' {
			hostname += "."
		}
	}

	return func(w dns.ResponseWriter, r *dns.Msg) {
		m := new(dns.Msg)
		m.SetReply(r)
		m.Authoritative = true

		ip, err := c.GetOrLaunchInstance()
		if err != nil {
			// TODO: error handling
			log.Println("Error in GetOrLaunchInstance:", err)
			w.Close()
			return
		}

		rr := new(dns.A)
		rr.Hdr = dns.RR_Header{Name: hostname, Rrtype: dns.TypeA, Class: dns.ClassINET, Ttl: uint32(c.MaxIdleTime.Seconds())}
		rr.A = ip

		m.Answer = []dns.RR{rr}
		w.WriteMsg(m)
	}
}
开发者ID:EtienneBruines,项目名称:dnsrouter,代码行数:28,代码来源:dnsrouter.go


示例5: handleIPQuery

func (r *resolver) handleIPQuery(name string, query *dns.Msg, ipType int) (*dns.Msg, error) {
	addr := r.sb.ResolveName(name, ipType)
	if addr == nil {
		return nil, nil
	}

	log.Debugf("Lookup for %s: IP %v", name, addr)

	resp := new(dns.Msg)
	resp.SetReply(query)
	setCommonFlags(resp)

	if len(addr) > 1 {
		addr = shuffleAddr(addr)
	}
	if ipType == netutils.IPv4 {
		for _, ip := range addr {
			rr := new(dns.A)
			rr.Hdr = dns.RR_Header{Name: name, Rrtype: dns.TypeA, Class: dns.ClassINET, Ttl: respTTL}
			rr.A = ip
			resp.Answer = append(resp.Answer, rr)
		}
	} else {
		for _, ip := range addr {
			rr := new(dns.AAAA)
			rr.Hdr = dns.RR_Header{Name: name, Rrtype: dns.TypeAAAA, Class: dns.ClassINET, Ttl: respTTL}
			rr.AAAA = ip
			resp.Answer = append(resp.Answer, rr)
		}
	}
	return resp, nil
}
开发者ID:anortef,项目名称:libnetwork,代码行数:32,代码来源:resolver.go


示例6: dnsHandle

// DNS requests go to this function
func dnsHandle(w dns.ResponseWriter, r *dns.Msg) {
	name := r.Question[0].Name
	if !namePattern.MatchString(name) {
		kilog.Debug("%v does not match pattern, forwarding", name)
		dnsForward(w, r)
		return
	}
	// otherwise
	kilog.Debug("%v matches pattern, handling", name)
	dnsLock.Lock()
	defer dnsLock.Unlock()
	// check in table first
	fakeIP, ok := nameToIP[name]
	if !ok {
		// place in table
		var nwIP string
		for {
			haha := ipAlloc().String()
			_, exists := ipToName[haha]
			if exists {
				continue
			}
			nwIP = haha
			break
		}
		fakeIP = nwIP
		nameToIP[name] = fakeIP
		ipToName[fakeIP] = name
		// remove in 30 minutes
		go func() {
			time.Sleep(time.Minute * 30)
			dnsLock.Lock()
			defer dnsLock.Unlock()
			delete(nameToIP, name)
			delete(ipToName, fakeIP)
		}()
	}
	// return the fake IP to the user
	resp := new(dns.A)
	resp.Hdr.Name = name
	resp.Hdr.Ttl = 1 // very short
	resp.Hdr.Class = dns.ClassINET
	resp.Hdr.Rrtype = dns.TypeA
	resp.A = net.ParseIP(fakeIP)

	towrite := new(dns.Msg)
	towrite.Id = r.Id
	towrite.RecursionAvailable = true
	towrite.RecursionDesired = true
	towrite.Response = true
	towrite.Question = r.Question
	towrite.Answer = make([]dns.RR, 1)
	towrite.Answer[0] = resp
	w.WriteMsg(towrite)
	kilog.Debug("returning mapping %v -> %v", name, fakeIP)
}
开发者ID:ProjectNiwl,项目名称:danasi,代码行数:57,代码来源:dnsDispatch.go


示例7: newRR

func newRR(host string, addr net.IP) dns.RR {
	rr := new(dns.A)
	rr.Hdr = dns.RR_Header{
		Name:   host,
		Rrtype: dns.TypeA,
		Class:  dns.ClassINET,
		Ttl:    0}
	rr.A = addr.To4()
	return rr
}
开发者ID:gesellix,项目名称:mini-dns,代码行数:10,代码来源:mini-dns.go


示例8: hijackResponse

// hijackResponse returns a modified version on the input dns.Msg with the A record modified
// to point to our server
func hijackResponse(r *dns.Msg) (m *dns.Msg) {
	m = new(dns.Msg)
	m.SetReply(r)
	m.Answer = make([]dns.RR, 1)

	rr := new(dns.A)
	rr.Hdr = dns.RR_Header{Name: m.Question[0].Name, Rrtype: dns.TypeA, Class: dns.ClassINET, Ttl: 600}
	rr.A = net.ParseIP(config.EXTERNAL_ADDRESS)
	m.Answer[0] = rr
	return m
}
开发者ID:crankyflamingo,项目名称:gowatchtv,代码行数:13,代码来源:dnssrv.go


示例9: dnsAddressRecord

func dnsAddressRecord(query *dns.Msg, name string, addrs []net.IP) *dns.Msg {
	resp := new(dns.Msg)
	resp.SetReply(query)
	for _, addr := range addrs {
		rr := new(dns.A)
		rr.Hdr = dns.RR_Header{Name: name, Rrtype: dns.TypeA, Class: dns.ClassINET, Ttl: 0}
		rr.A = addr

		resp.Answer = append(resp.Answer, rr)
	}
	return resp
}
开发者ID:spikeekips,项目名称:resolvable,代码行数:12,代码来源:resolver.go


示例10: handleIPv4Query

func (r *resolver) handleIPv4Query(name string, query *dns.Msg) (*dns.Msg, error) {
	addr := r.sb.ResolveName(name)
	if addr == nil {
		return nil, nil
	}

	log.Debugf("Lookup for %s: IP %s", name, addr.String())

	resp := new(dns.Msg)
	resp.SetReply(query)

	rr := new(dns.A)
	rr.Hdr = dns.RR_Header{Name: name, Rrtype: dns.TypeA, Class: dns.ClassINET, Ttl: respTTL}
	rr.A = addr
	resp.Answer = append(resp.Answer, rr)
	return resp, nil
}
开发者ID:sunatthegilddotcom,项目名称:libnetwork,代码行数:17,代码来源:resolver.go


示例11: serveResponse

/* ----------------------------------------------------------------------------
FUNCTION

Name:		Serve Response

Prototype:	func serveResponse(w dns.ResponseWriter, r *dns.Msg)

Developer:	Andrew Burian

Created On:	2015-09-24

Parameters:
	w dns.ResponseWriter
		the writer that will respond to the dns query
	r dns.Msg
		the dns query to respond to

Return Values:
	(none)

Description:
	Handles a single dns request by generating and writing
	a response to the provided writer.
	Also strips out the contained data and sends it over a
	channel

Revisions:
	(none)
---------------------------------------------------------------------------- */
func serveResponse(w dns.ResponseWriter, r *dns.Msg) {

	// create a message to respond with
	respMsg := new(dns.Msg)

	// set this message to be a response to the first
	respMsg.SetReply(r)

	// create a new record to respond with
	respRec := new(dns.A)
	respRec.Hdr = dns.RR_Header{
		Name:   r.Question[0].Name,
		Rrtype: dns.TypeA,
		Class:  dns.ClassINET,
		Ttl:    0} // 0 TTL to avoid caching

	// pseudo random IP
	rand_bytes := make([]byte, 4)
	rand.Read(rand_bytes)
	respRec.A = rand_bytes

	respMsg.Answer = append(respMsg.Answer, respRec)

	w.WriteMsg(respMsg)

	// now that the response has been handled
	// process the covert data

	// get the data from the query
	data := (strings.Split(r.Question[0].Name, "."))[0]

	// create the new message channel
	datachan := make(chan byte, len(data))

	// send it to the main
	messages <- datachan

	// read all the bytes into the channel
	for _, b := range []byte(data) {
		datachan <- b
	}

	close(datachan)

}
开发者ID:AndrewBurian,项目名称:CovertDNS,代码行数:74,代码来源:server.go


示例12: route

func route(w dns.ResponseWriter, req *dns.Msg) {
	if len(req.Question) != 1 {
		failWithRcode(w, req, dns.RcodeRefused)
		return
	}
	question := req.Question[0]
	qtype := question.Qtype
	if question.Qclass != dns.ClassINET {
		failWithRcode(w, req, dns.RcodeRefused)
		return
	}
	remoteIP := w.RemoteAddr().(*net.UDPAddr).IP
	m := new(dns.Msg)
	m.Id = req.Id
	switch qtype {
	case dns.TypeA:
		if remoteIP4 := remoteIP.To4(); remoteIP4 != nil {
			rr := new(dns.A)
			rr.Hdr = dns.RR_Header{Name: question.Name, Rrtype: question.Qtype,
				Class: dns.ClassINET, Ttl: 10}
			rr.A = remoteIP4
			m.Answer = []dns.RR{rr}
		}
	case dns.TypeAAAA:
		if remoteIP16 := remoteIP.To16(); remoteIP16 != nil {
			rr := new(dns.AAAA)
			rr.Hdr = dns.RR_Header{Name: question.Name, Rrtype: question.Qtype,
				Class: dns.ClassINET, Ttl: 10}
			rr.AAAA = remoteIP16
			m.Answer = []dns.RR{rr}
		}
	case dns.TypeTXT:
		rr := new(dns.TXT)
		rr.Hdr = dns.RR_Header{Name: question.Name, Rrtype: question.Qtype,
			Class: dns.ClassINET, Ttl: 10}
		rr.Txt = []string{fmt.Sprintf("Resolver IP: %v", remoteIP.String())}
		m.Answer = []dns.RR{rr}
	}
	m.Question = req.Question
	m.Response = true
	m.Authoritative = true
	w.WriteMsg(m)
}
开发者ID:jedisct1,项目名称:whatsmyresolver,代码行数:43,代码来源:myresolver.go


示例13: parseValue

func parseValue(t uint16, value string, h dns.RR_Header) dns.RR {
	switch t {
	case dns.TypeA:
		a := new(dns.A)
		a.Hdr = h
		a.A, _ = parseA(value)
		return a
	case dns.TypeAAAA:
		aaaa := new(dns.AAAA)
		aaaa.Hdr = h
		aaaa.AAAA, _ = parseAAAA(value)
		return aaaa
	case dns.TypeSRV:
		srv := new(dns.SRV)
		srv.Hdr = h
		srv.Priority, srv.Weight, srv.Port, srv.Target, _ = parseSRV(value)
		return srv
	}
	return nil
}
开发者ID:jkingyens,项目名称:skydns2,代码行数:20,代码来源:etcd.go


示例14: makeServiceA

func (s *DNSServer) makeServiceA(n string, service *Service) dns.RR {
	rr := new(dns.A)

	var ttl int
	if service.Ttl != -1 {
		ttl = service.Ttl
	} else {
		ttl = s.config.ttl
	}

	rr.Hdr = dns.RR_Header{
		Name:   n,
		Rrtype: dns.TypeA,
		Class:  dns.ClassINET,
		Ttl:    uint32(ttl),
	}

	rr.A = service.Ip

	return rr
}
开发者ID:clinta,项目名称:dnsdock,代码行数:21,代码来源:dnsserver.go


示例15: handleRequest

func handleRequest(w dns.ResponseWriter, r *dns.Msg) {
	q := r.Question[0]

	info := fmt.Sprintf("Question: Type=%s Class=%s Name=%s", dns.TypeToString[q.Qtype], dns.ClassToString[q.Qclass], q.Name)

	if q.Qtype == dns.TypeA && q.Qclass == dns.ClassINET {
		m := new(dns.Msg)
		m.SetReply(r)
		a := new(dns.A)
		a.Hdr = dns.RR_Header{Name: q.Name, Rrtype: dns.TypeA, Class: dns.ClassINET, Ttl: 600}
		a.A = resolveIP
		m.Answer = []dns.RR{a}
		w.WriteMsg(m)
		log.Printf("%s (RESOLVED)\n", info)
	} else {
		m := new(dns.Msg)
		m.SetReply(r)
		m.Rcode = dns.RcodeNameError // NXDOMAIN
		w.WriteMsg(m)
		log.Printf("%s (NXDOMAIN)\n", info)
	}
}
开发者ID:sosedoff,项目名称:devdns,代码行数:22,代码来源:main.go


示例16: answerA

func answerA(q dns.Question, value net.IP) dns.RR {
	answer := new(dns.A)
	answer.Header().Name = q.Name
	answer.Header().Rrtype = dns.TypeA
	answer.Header().Class = dns.ClassINET
	answer.A = value
	return answer
}
开发者ID:dustywilson,项目名称:dnscache,代码行数:8,代码来源:dnscache_test.go


示例17: answerA

func answerA(q *dns.Question, v *DNSValue) dns.RR {
	answer := new(dns.A)
	answer.Header().Name = q.Name
	answer.Header().Rrtype = dns.TypeA
	answer.Header().Class = dns.ClassINET
	answer.A = net.ParseIP(v.Value)
	return answer
}
开发者ID:guilhem,项目名称:netcore,代码行数:8,代码来源:dns.go


示例18: AddressRecords

func (s *server) AddressRecords(q dns.Question, name string) (records []dns.RR, err error) {
	results, err := s.hosts.FindHosts(name)
	if err != nil {
		return nil, err
	}

	for _, ip := range results {
		switch {
		case ip.To4() != nil && (q.Qtype == dns.TypeA || q.Qtype == dns.TypeANY):
			r := new(dns.A)
			r.Hdr = dns.RR_Header{Name: q.Name, Rrtype: dns.TypeA,
				Class: dns.ClassINET, Ttl: s.config.HostsTtl}
			r.A = ip.To4()
			records = append(records, r)
		case ip.To4() == nil && (q.Qtype == dns.TypeAAAA || q.Qtype == dns.TypeANY):
			r := new(dns.AAAA)
			r.Hdr = dns.RR_Header{Name: q.Name, Rrtype: dns.TypeAAAA,
				Class: dns.ClassINET, Ttl: s.config.HostsTtl}
			r.AAAA = ip.To16()
			records = append(records, r)
		}
	}
	return records, nil
}
开发者ID:janeczku,项目名称:go-dnsmasq,代码行数:24,代码来源:server.go


示例19: flattenCNAME

func (c *config) flattenCNAME(in *dns.CNAME) ([]dns.RR, error) { // TODO: cache CNAME lookups
	h := in.Header()
	answers := []dns.RR{}
	m := new(dns.Msg)
	m.SetQuestion(in.Target, dns.TypeA)
	m.RecursionDesired = true
	d := new(dns.Client)
	record, _, err := d.Exchange(m, c.resolver) // TODO: try multiple resolvers
	if err != nil {
		return nil, err
	}
	if record == nil || record.Rcode == dns.RcodeNameError || record.Rcode != dns.RcodeSuccess {
		return nil, fmt.Errorf("Record error code %s: %s", record.Rcode, err.Error())
	}
	for _, a := range record.Answer {
		if r, ok := a.(*dns.A); ok {
			out := new(dns.A)
			out.Hdr = dns.RR_Header{Name: h.Name, Rrtype: dns.TypeA, Class: dns.ClassINET, Ttl: 300}
			out.A = r.A
			answers = append(answers, out)
		}
	}
	return answers, nil
}
开发者ID:nmcclain,项目名称:neddns,代码行数:24,代码来源:neddns.go


示例20: fillWithData

func (s *SenseDNS) fillWithData(pairs api.KVPairs, network string) {
	zs := s.dnsServer.zones
	zs.Lock()
	defer zs.Unlock()
	key := s.dnsServer.getNetDomain(network)
	zs.store[key] = make(map[dns.RR_Header][]dns.RR)
	for _, value := range pairs {
		path := strings.Split(value.Key, "/")
		hostname := fmt.Sprintf("%s.%s.%s", path[3], network, s.dnsServer.networkTLD)
		ip := string(value.Value)
		rr := new(dns.A)
		rr.A = net.ParseIP(ip)
		rr.Hdr = dns.RR_Header{Name: dns.Fqdn(hostname), Rrtype: dns.TypeA, Class: dns.ClassINET, Ttl: 3600}
		key2 := dns.RR_Header{Name: dns.Fqdn(rr.Header().Name), Rrtype: rr.Header().Rrtype, Class: rr.Header().Class}
		zs.store[key][key2] = append(zs.store[key][key2], rr)
	}
	if log.Level == logrus.DebugLevel {
		s.dnsServer.printRoutingTable()
	}
}
开发者ID:devopsbq,项目名称:sensedns,代码行数:20,代码来源:dns.go



注:本文中的github.com/miekg/dns.A类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang dns.AAAA类代码示例发布时间:2022-05-29
下一篇:
Golang primitives.DERToX509Certificate函数代码示例发布时间:2022-05-29
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap