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

Golang dns.Conn类代码示例

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

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



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

示例1: main

func main() {
	c, err := dns.ClientConfigFromFile("/etc/resolv.conf")
	if len(os.Args) != 2 || err != nil {
		fmt.Printf("%s DOMAIN\n", os.Args[0])
		os.Exit(1)
	}
	m := new(dns.Msg)
	m.MsgHdr.RecursionDesired = true //only set this bit
	m.Question = make([]dns.Question, 1)
	m.Question[0] = dns.Question{os.Args[1], dns.TypeDNSKEY, dns.ClassINET}

	d := new(dns.Conn)
	d.RemoteAddr = c.Servers[0]
	in, err := dns.SimpleQuery("udp", d, m)
	if in != nil {
		if in.Rcode != dns.RcodeSuccess {
			fmt.Printf(" *** invalid answer name %s after DNSKEY query for %s\n", os.Args[1], os.Args[1])
			os.Exit(1)
		}
		// Stuff must be in the answer section
		for _, k := range in.Answer {
			// Foreach key would need to provide a DS records, both sha1 and sha256
			if key, ok := k.(*dns.RR_DNSKEY); ok {
				ds := key.ToDS(dns.HashSHA1)
				ds.Hdr.Ttl = 0
				fmt.Printf("%v\n", ds)
				ds = key.ToDS(dns.HashSHA256)
				ds.Hdr.Ttl = 0
				fmt.Printf("%v\n", ds)
			}
		}
	} else {
		fmt.Printf("*** error: %s\n", err.String())
	}
}
开发者ID:elazarl,项目名称:godns,代码行数:35,代码来源:key2ds.go


示例2: main

func main() {
	c, _ := dns.ClientConfigFromFile("/etc/resolv.conf")
	if len(os.Args) != 2 {
		fmt.Printf("%s DOMAIN\n", os.Args[0])
		os.Exit(1)
	}

	m := new(dns.Msg)
	m.Question = make([]dns.Question, 1)
	d := new(dns.Conn)
	d.RemoteAddr = c.Servers[0]
	for _, a := range addresses(d, os.Args[0]) {
		d.RemoteAddr = a
		if err := d.Dial("udp"); err != nil {
			fmt.Printf("%v\n", err)
			os.Exit(1)
		}

		m.Question[0] = dns.Question{"version.bind.", dns.TypeTXT, dns.ClassCHAOS}
		in, _ := dns.SimpleQuery("udp", d, m)
		if in != nil && in.Answer != nil {
			fmt.Printf("%v\n", in.Answer[0])
		}
		m.Question[0] = dns.Question{"hostname.bind.", dns.TypeTXT, dns.ClassCHAOS}
		in, _ = dns.SimpleQuery("udp", d, m)
		if in != nil && in.Answer != nil {
			fmt.Printf("%v\n", in.Answer[0])
		}
	}
}
开发者ID:elazarl,项目名称:godns,代码行数:30,代码来源:chaos.go


示例3: handle

func handle(c *dns.Conn, in *dns.Msg) {
	if in.MsgHdr.Response == true {
		return // We don't do responses
	}
	answer := reply(c, in)
	c.Write(answer)
}
开发者ID:elazarl,项目名称:godns,代码行数:7,代码来源:reflect.go


示例4: newConnMsg

func newConnMsg(qname, nameserver string, attempts int, qtype, qclass uint16, aa, ad, cd, rd, dnssec, nsid bool) (*dns.Conn, *dns.Msg) {
	d := new(dns.Conn)
	d.RemoteAddr = nameserver
	d.Attempts = attempts

	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)
	if dnssec || nsid {
		opt := new(dns.RR_OPT)
		opt.SetDo()
		opt.SetVersion(0)
		opt.SetUDPSize(dns.DefaultMsgSize)
		if nsid {
			opt.SetNsid("")
		}
		m.Extra = make([]dns.RR, 1)
		m.Extra[0] = opt
	}
	m.Question[0] = dns.Question{qname, qtype, qclass}
	m.Id = dns.Id()
	return d, m
}
开发者ID:elazarl,项目名称:godns,代码行数:26,代码来源:q.go


示例5: reply

func reply(c *dns.Conn, i *dns.Msg) {
	out, err := doFunkensturm(i)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Error: %s\n", err.String())
		return
	}
	if out != nil {
		c.Write(out)
	}
}
开发者ID:elazarl,项目名称:godns,代码行数:10,代码来源:funkensturm.go


示例6: handleNotifyOut

func handleNotifyOut(addr string) {
	if Zone.name == "" || !Zone.correct {
		return
	}
	d := new(dns.Conn)
	d.RemoteAddr = addr
	m := new(dns.Msg)
	m.SetNotify(Zone.name)
	fmt.Printf("Sending notifies: zone is ok\n")
	dns.QueryRequest <- &dns.Query{Conn: d, Query: m}
}
开发者ID:elazarl,项目名称:godns,代码行数:11,代码来源:xfr.go


示例7: handleXfrIn

func handleXfrIn(i *dns.Msg) os.Error {
	q := new(dns.Msg)
	q.SetAxfr(i.Question[0].Name)

	m := make(chan *dns.Xfr)
	fmt.Printf("Preparing Xfr for %s\n", i.Question[0].Name)

	d := new(dns.Conn)
	d.RemoteAddr = "127.0.0.1:53"
	err := d.Dial("tcp")
	if err != nil {
		return err
	}
	defer d.Close()

	fmt.Printf("Calling 127.0.0.1 successful\n")
	go d.XfrRead(q, m)

	Zone.name = i.Question[0].Name
	j := 0
	for x := range m {
		Zone.rrs[j] = x.RR
		j++
	}
	fmt.Printf("Success retrieved %s\n", Zone.name)
	Zone.size = j
	return nil
}
开发者ID:elazarl,项目名称:godns,代码行数:28,代码来源:xfr.go


示例8: handleNotify

func handleNotify(d *dns.Conn, i *dns.Msg) os.Error {
	if i.IsNotify() {
		fmt.Printf("Incoming notify seen\n")
		q := new(dns.Msg)
		q.SetReply(i)
		err := d.WriteMsg(q)
		if err != nil {
			return err
		}
		err = handleXfrIn(i)
		if err != nil {
			return err
		}
	}
	return nil
}
开发者ID:elazarl,项目名称:godns,代码行数:16,代码来源:xfr.go


示例9: main

func main() {
	var sserver *string = flag.String("sserver", "127.0.0.1:8053", "Set the listener address")
	var rserver *string = flag.String("rserver", "127.0.0.1:53", "Remote server address(es), seperate with commas")
	verbose = flag.Bool("verbose", false, "Print packet as it flows through") // verbose needs to be global
	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "Usage: %s\n", os.Args[0])
		flag.PrintDefaults()
	}
	flag.Parse()

	resolvers := strings.Split(*rserver, ",", -1)
	qr = make([]*dns.Resolver, len(resolvers))
	for i, ra := range resolvers {
		d := new(dns.Conn)
		d.RemoteAddr = addr
		qr[i] = d
	}

	f = funkensturm()
	ok := f.Setup()
	if !ok {
		fmt.Fprintf(os.Stderr, "Setup failed")
		return
	}

	err := make(chan os.Error)
	go udp(*sserver, err)
	go tcp(*sserver, err)

forever:
	for {
		select {
		case e := <-err:
			fmt.Printf("Error received, stopping: %s\n", e.String())
			break forever
		case <-signal.Incoming:
			fmt.Printf("Signal received, stopping")
			break forever
		}
	}
	close(err)
}
开发者ID:elazarl,项目名称:godns,代码行数:42,代码来源:funkensturm.go


示例10: handleXfrOut

func handleXfrOut(d *dns.Conn, i *dns.Msg) os.Error {
	if i.IsAxfr() {
		fmt.Printf("Incoming Axfr request seen\n")
		if i.Question[0].Name == Zone.name {
			fmt.Printf("Matches current zone\n")
			if !Zone.correct {
				fmt.Printf("Zone was not deemed correct\n")
				if err := d.WriteMsg(i); err != nil {
					return err
				}
				return nil
			} else {
				fmt.Printf("Zone was correct\n")
			}

			m := make(chan *dns.Xfr)
			e := make(chan os.Error)
			go d.XfrWrite(i, m, e)
			for j := 0; j < Zone.size; j++ {
				select {
				case m <- &dns.Xfr{Add: true, RR: Zone.rrs[j]}: //
				case err := <-e:
					return err
				}
			}
			close(m)
		} else {
			fmt.Printf("No matching zone found\n")
			if err := d.WriteMsg(i); err != nil {
				return err
			}
		}
	}
	return nil
}
开发者ID:elazarl,项目名称:godns,代码行数:35,代码来源:xfr.go


示例11: main

func main() {
	if len(os.Args) != 2 {
		fmt.Printf("%s DOMAIN\n", os.Args[0])
		os.Exit(1)
	}
	d := new(dns.Conn)
	c, err := dns.ClientConfigFromFile("/etc/resolv.conf")
	// Errorchecking
	d.RemoteAddr = c.Servers[0]

	m := new(dns.Msg)
	m.Id = dns.Id()
	m.MsgHdr.RecursionDesired = true
	m.Question = make([]dns.Question, 1)
	m.Question[0] = dns.Question{os.Args[1], dns.TypeMX, dns.ClassINET}

	err = d.Dial("udp")
	if err != nil {
		fmt.Printf("*** error: %s\n", err.String())
		os.Exit(1)
	}

	in, err := dns.SimpleQuery("udp", d, m)
	if in != nil {
		if in.Rcode != dns.RcodeSuccess {
			fmt.Printf(" *** invalid answer name %s after MX query for %s\n", os.Args[1], os.Args[1])
			os.Exit(1)
		}
		// Stuff must be in the answer section
		for _, a := range in.Answer {
			fmt.Printf("%v\n", a)
		}
	} else {
		fmt.Printf("*** error: %s\n", err.String())
	}
}
开发者ID:elazarl,项目名称:godns,代码行数:36,代码来源:mx.go


示例12: qhandle

// reply checking 'n stuff
func qhandle(d *dns.Conn, i *dns.Msg) {
	o, err := d.ExchangeMsg(i, false)
	dns.QueryReply <- &dns.Query{Query: i, Reply: o, Conn: d, Err: err}
	d.Close()
}
开发者ID:elazarl,项目名称:godns,代码行数:6,代码来源:q.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang dns.Msg类代码示例发布时间:2022-05-24
下一篇:
Golang dns.Client类代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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