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

Golang dns.Transfer类代码示例

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

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



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

示例1: Transfer

func (s *Service) Transfer(zone string) ([]dns.RR, error) {
	m := new(dns.Msg)
	m.SetAxfr(zone)

	h, err := s.ServerPort()
	if err != nil {
		return nil, err
	}

	tr := new(dns.Transfer)
	a, err := tr.In(m, h)
	if err != nil {
		return nil, err
	}

	var res []dns.RR
	for ex := range a {
		if ex.Error != nil {
			return nil, ex.Error
		}
		res = append(res, ex.RR...)
	}

	return res, nil
}
开发者ID:ozym,项目名称:zone,代码行数:25,代码来源:service.go


示例2: proxy

func proxy(addr string, w dns.ResponseWriter, req *dns.Msg) {
	transport := "udp"
	if _, ok := w.RemoteAddr().(*net.TCPAddr); ok {
		transport = "tcp"
	}
	if isTransfer(req) {
		if transport != "tcp" {
			dns.HandleFailed(w, req)
			return
		}
		t := new(dns.Transfer)
		c, err := t.In(req, addr)
		if err != nil {
			dns.HandleFailed(w, req)
			return
		}
		if err = t.Out(w, req, c); err != nil {
			dns.HandleFailed(w, req)
			return
		}
		return
	}
	c := &dns.Client{Net: transport}
	resp, _, err := c.Exchange(req, addr)
	if err != nil {
		dns.HandleFailed(w, req)
		return
	}
	w.WriteMsg(resp)
}
开发者ID:40a,项目名称:dns-reverse-proxy,代码行数:30,代码来源:dns_reverse_proxy.go


示例3: AXFR

// AXFR attempts a zone transfer for the domain.
func AXFR(domain, serverAddr string) *Tsk {
	t := newTsk("axfr")
	servers, err := LookupNS(domain, serverAddr)
	if err != nil {
		t.SetErr(err)
		return t
	}

	for _, s := range servers {
		tr := dns.Transfer{}
		m := &dns.Msg{}
		m.SetAxfr(dns.Fqdn(domain))
		in, err := tr.In(m, s+":53")
		if err != nil {
			t.SetErr(err)
			return t
		}
		for ex := range in {
			for _, a := range ex.RR {
				var ip, hostname string
				switch v := a.(type) {
				case *dns.A:
					ip = v.A.String()
					hostname = v.Hdr.Name
				case *dns.AAAA:
					ip = v.AAAA.String()
					hostname = v.Hdr.Name
				case *dns.PTR:
					ip = v.Hdr.Name
					hostname = v.Ptr
				case *dns.NS:
					cip, err := LookupName(v.Ns, serverAddr)
					if err != nil || cip == "" {
						continue
					}
					ip = cip
					hostname = v.Ns
				case *dns.CNAME:
					cip, err := LookupName(v.Target, serverAddr)
					if err != nil || cip == "" {
						continue
					}
					hostname = v.Hdr.Name
					ip = cip
				case *dns.SRV:
					cip, err := LookupName(v.Target, serverAddr)
					if err != nil || ip == "" {
						continue
					}
					ip = cip
					hostname = v.Target
				default:
					continue
				}
				t.AddResult(ip, strings.TrimRight(hostname, "."))
			}
		}
	}
	return t
}
开发者ID:tomsteele,项目名称:blacksheepwall,代码行数:61,代码来源:axfr.go


示例4: transfer

func (e *Equipment) transfer() ([]dns.RR, error) {
	m := new(dns.Msg)
	m.SetAxfr(e.Zone)

	port := e.Port
	if port == "" {
		port = DEF_PORT
	}

	s, err := net.LookupHost(e.Server)
	if err != nil {
		return nil, err
	}

	tr := new(dns.Transfer)
	a, err := tr.In(m, net.JoinHostPort(s[0], port))
	if err != nil {
		return nil, err
	}

	var res []dns.RR
	for ex := range a {
		if ex.Error != nil {
			return nil, ex.Error
		}
		res = append(res, ex.RR...)
	}

	return res, nil
}
开发者ID:ozym,项目名称:zone,代码行数:30,代码来源:equipment.go


示例5: list

func (r *RFC2136Provider) list() ([]dns.RR, error) {
	logrus.Debugf("Fetching records for '%s'", r.zoneName)
	t := new(dns.Transfer)
	t.TsigSecret = map[string]string{r.tsigKeyName: r.tsigSecret}

	m := new(dns.Msg)
	m.SetAxfr(r.zoneName)
	m.SetTsig(r.tsigKeyName, dns.HmacMD5, 300, time.Now().Unix())

	env, err := t.In(m, r.nameserver)
	if err != nil {
		return nil, fmt.Errorf("Failed to fetch records via AXFR: %v", err)
	}

	records := make([]dns.RR, 0)
	for e := range env {
		if e.Error != nil {
			logrus.Errorf("AXFR envelope error: %v", e.Error)
			continue
		}
		records = append(records, e.RR...)
	}

	return records, nil
}
开发者ID:rancher,项目名称:external-dns,代码行数:25,代码来源:rfc2136.go


示例6: TransferIn

// TransferIn retrieves the zone from the masters, parses it and sets it live.
func (z *Zone) TransferIn() error {
	if len(z.TransferFrom) == 0 {
		return nil
	}
	m := new(dns.Msg)
	m.SetAxfr(z.origin)

	z1 := z.Copy()
	var (
		Err error
		tr  string
	)

Transfer:
	for _, tr = range z.TransferFrom {
		t := new(dns.Transfer)
		c, err := t.In(m, tr)
		if err != nil {
			log.Printf("[ERROR] Failed to setup transfer `%s' with `%s': %v", z.origin, tr, err)
			Err = err
			continue Transfer
		}
		for env := range c {
			if env.Error != nil {
				log.Printf("[ERROR] Failed to parse transfer `%s': %v", z.origin, env.Error)
				Err = env.Error
				continue Transfer
			}
			for _, rr := range env.RR {
				if err := z1.Insert(rr); err != nil {
					log.Printf("[ERROR] Failed to parse transfer `%s': %v", z.origin, err)
					Err = err
					continue Transfer
				}
			}
		}
		Err = nil
		break
	}
	if Err != nil {
		log.Printf("[ERROR] Failed to transfer %s: %s", z.origin, Err)
		return Err
	}

	z.Tree = z1.Tree
	z.Apex = z1.Apex
	*z.Expired = false
	log.Printf("[INFO] Transferred: %s from %s", z.origin, tr)
	return nil
}
开发者ID:yuewko,项目名称:coredns,代码行数:51,代码来源:secondary.go


示例7: ZoneTransfer

func ZoneTransfer(domain string) Results {
	results := NewResultSet()
	fqdn := dns.Fqdn(domain)

	servers, err := net.LookupNS(domain)
	if err != nil {
		log.Fatal(err)
	}

	for _, server := range servers {
		msg := new(dns.Msg)
		msg.SetAxfr(fqdn)

		transfer := new(dns.Transfer)
		answerChan, err := transfer.In(msg, net.JoinHostPort(server.Host, "53"))
		if err != nil {
			log.Println(err)
			continue
		}

		for envelope := range answerChan {
			if envelope.Error != nil {
				log.Println(envelope.Error)
				break
			}

			for _, rr := range envelope.RR {
				switch v := rr.(type) {
				case *dns.A:
					results.Add(strings.TrimRight(v.Header().Name, "."), v.A.String())
				case *dns.AAAA:
					results.Add(strings.TrimRight(v.Header().Name, "."), v.AAAA.String())
				default:
				}
			}
		}
	}

	return results.Results()
}
开发者ID:jrozner,项目名称:sonar,代码行数:40,代码来源:zonetransfer.go


示例8: ServeDNS

// Serve an AXFR (and fallback of IXFR) as well.
func (x Xfr) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
	state := middleware.State{W: w, Req: r}
	if !x.TransferAllowed(state) {
		return dns.RcodeServerFailure, nil
	}
	if state.QType() != dns.TypeAXFR && state.QType() != dns.TypeIXFR {
		return 0, fmt.Errorf("xfr called with non transfer type: %d", state.QType())
	}

	records := x.All()
	if len(records) == 0 {
		return dns.RcodeServerFailure, nil
	}

	ch := make(chan *dns.Envelope)
	defer close(ch)
	tr := new(dns.Transfer)
	go tr.Out(w, r, ch)

	j, l := 0, 0
	records = append(records, records[0]) // add closing SOA to the end
	log.Printf("[INFO] Outgoing transfer of %d records of zone %s to %s started", len(records), x.origin, state.IP())
	for i, r := range records {
		l += dns.Len(r)
		if l > transferLength {
			ch <- &dns.Envelope{RR: records[j:i]}
			l = 0
			j = i
		}
	}
	if j < len(records) {
		ch <- &dns.Envelope{RR: records[j:]}
	}

	w.Hijack()
	// w.Close() // Client closes connection
	return dns.RcodeSuccess, nil
}
开发者ID:yuewko,项目名称:coredns,代码行数:39,代码来源:xfr.go


示例9: handleReflect

func handleReflect(w dns.ResponseWriter, r *dns.Msg) {
	reflectHandled += 1
	if reflectHandled%1000 == 0 {
		fmt.Printf("Served %d reflections\n", reflectHandled)
	}
	var (
		v4  bool
		rr  dns.RR
		str string
		a   net.IP
	)
	m := new(dns.Msg)
	m.SetReply(r)
	m.Compress = *compress
	if ip, ok := w.RemoteAddr().(*net.UDPAddr); ok {
		str = "Port: " + strconv.Itoa(ip.Port) + " (udp)"
		a = ip.IP
		v4 = a.To4() != nil
	}
	if ip, ok := w.RemoteAddr().(*net.TCPAddr); ok {
		str = "Port: " + strconv.Itoa(ip.Port) + " (tcp)"
		a = ip.IP
		v4 = a.To4() != nil
	}

	if v4 {
		rr = new(dns.A)
		rr.(*dns.A).Hdr = dns.RR_Header{Name: dom, Rrtype: dns.TypeA, Class: dns.ClassINET, Ttl: 0}
		rr.(*dns.A).A = a.To4()
	} else {
		rr = new(dns.AAAA)
		rr.(*dns.AAAA).Hdr = dns.RR_Header{Name: dom, Rrtype: dns.TypeAAAA, Class: dns.ClassINET, Ttl: 0}
		rr.(*dns.AAAA).AAAA = a
	}

	t := new(dns.TXT)
	t.Hdr = dns.RR_Header{Name: dom, Rrtype: dns.TypeTXT, Class: dns.ClassINET, Ttl: 0}
	t.Txt = []string{str}

	switch r.Question[0].Qtype {
	case dns.TypeTXT:
		m.Answer = append(m.Answer, t)
		m.Extra = append(m.Extra, rr)
	default:
		fallthrough
	case dns.TypeAAAA, dns.TypeA:
		m.Answer = append(m.Answer, rr)
		m.Extra = append(m.Extra, t)

	case dns.TypeAXFR, dns.TypeIXFR:
		c := make(chan *dns.Envelope)
		tr := new(dns.Transfer)
		defer close(c)
		err := tr.Out(w, r, c)
		if err != nil {
			return
		}
		soa, _ := dns.NewRR(`whoami.miek.nl. 0 IN SOA linode.atoom.net. miek.miek.nl. 2009032802 21600 7200 604800 3600`)
		c <- &dns.Envelope{RR: []dns.RR{soa, t, rr, soa}}
		w.Hijack()
		// w.Close() // Client closes connection
		return

	}

	if r.IsTsig() != nil {
		if w.TsigStatus() == nil {
			m.SetTsig(r.Extra[len(r.Extra)-1].(*dns.TSIG).Hdr.Name, dns.HmacMD5, 300, time.Now().Unix())
		} else {
			println("Status", w.TsigStatus().Error())
		}
	}
	if *printf {
		fmt.Printf("%v\n", m.String())
	}
	// set TC when question is tc.miek.nl.
	if m.Question[0].Name == "tc.miek.nl." {
		m.Truncated = true
		// send half a message
		buf, _ := m.Pack()
		w.Write(buf[:len(buf)/2])
		return
	}
	w.WriteMsg(m)
}
开发者ID:hobbeswalsh,项目名称:GolangStuffs,代码行数:85,代码来源:reflect.go


示例10: main


//.........这里部分代码省略.........
		if len(qtype) == 0 {
			qtype = append(qtype, dns.TypeNS)
		}
	}
	if len(qtype) == 0 {
		qtype = append(qtype, dns.TypeA)
	}
	if len(qclass) == 0 {
		qclass = append(qclass, dns.ClassINET)
	}

	if len(nameserver) == 0 {
		conf, err := dns.ClientConfigFromFile("/etc/resolv.conf")
		if err != nil {
			fmt.Fprintln(os.Stderr, err)
			os.Exit(2)
		}
		nameserver = "@" + conf.Servers[0]
	}

	nameserver = string([]byte(nameserver)[1:]) // chop off @
	// if the nameserver is from /etc/resolv.conf the [ and ] are already
	// added, thereby breaking net.ParseIP. Check for this and don't
	// fully qualify such a name
	if nameserver[0] == '[' && nameserver[len(nameserver)-1] == ']' {
		nameserver = nameserver[1 : len(nameserver)-1]
	}
	if i := net.ParseIP(nameserver); i != nil {
		nameserver = net.JoinHostPort(nameserver, strconv.Itoa(*port))
	} else {
		nameserver = dns.Fqdn(nameserver) + ":" + strconv.Itoa(*port)
	}
	c := new(dns.Client)
	t := new(dns.Transfer)
	c.Net = "udp"
	if *four {
		c.Net = "udp4"
	}
	if *six {
		c.Net = "udp6"
	}
	if *tcp {
		c.Net = "tcp"
		if *four {
			c.Net = "tcp4"
		}
		if *six {
			c.Net = "tcp6"
		}
	}

	m := new(dns.Msg)
	m.MsgHdr.Authoritative = *aa
	m.MsgHdr.AuthenticatedData = *ad
	m.MsgHdr.CheckingDisabled = *cd
	m.MsgHdr.RecursionDesired = *rd
	m.Question = make([]dns.Question, 1)
	m.Opcode = dns.OpcodeQuery
	if op, ok := dns.StringToOpcode[strings.ToUpper(*opcode)]; ok {
		m.Opcode = op
	}
	m.Rcode = dns.RcodeSuccess
	if rc, ok := dns.StringToRcode[strings.ToUpper(*rcode)]; ok {
		m.Rcode = rc
	}
开发者ID:valm0unt,项目名称:exdns,代码行数:66,代码来源:q.go


示例11: AXFR

// AXFR attempts a zone transfer for the domain.
func AXFR(domain, serverAddr string) (string, Results, error) {
	task := "axfr"
	results := Results{}

	servers, err := LookupNS(domain, serverAddr)
	if err != nil {
		return task, results, err
	}

	for _, s := range servers {
		tr := dns.Transfer{}
		m := &dns.Msg{}
		m.SetAxfr(dns.Fqdn(domain))
		in, err := tr.In(m, s+":53")
		if err != nil {
			return task, results, err
		}
		for ex := range in {
			for _, a := range ex.RR {
				var ip, hostname string
				switch v := a.(type) {
				case *dns.A:
					ip = v.A.String()
					hostname = v.Hdr.Name
				case *dns.AAAA:
					ip = v.AAAA.String()
					hostname = v.Hdr.Name
				case *dns.PTR:
					ip = v.Hdr.Name
					hostname = v.Ptr
				case *dns.NS:
					cip, err := LookupName(v.Ns, serverAddr)
					if err != nil || cip == "" {
						continue
					}
					ip = cip
					hostname = v.Ns
				case *dns.CNAME:
					cip, err := LookupName(v.Target, serverAddr)
					if err != nil || cip == "" {
						continue
					}
					hostname = v.Hdr.Name
					ip = cip
				case *dns.SRV:
					cip, err := LookupName(v.Target, serverAddr)
					if err != nil || ip == "" {
						continue
					}
					ip = cip
					hostname = v.Target
				default:
					continue
				}
				results = append(results, Result{
					Source:   task,
					IP:       ip,
					Hostname: strings.TrimRight(hostname, "."),
				})
			}
		}
	}
	return task, results, nil
}
开发者ID:intfrr,项目名称:blacksheepwall,代码行数:65,代码来源:axfr.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang log.Errorf函数代码示例发布时间:2022-05-29
下一篇:
Golang dns.TXT类代码示例发布时间: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