當前位置: 首頁>>代碼示例>>Golang>>正文


Golang dns.ClientConfigFromFile函數代碼示例

本文整理匯總了Golang中github.com/miekg/dns.ClientConfigFromFile函數的典型用法代碼示例。如果您正苦於以下問題:Golang ClientConfigFromFile函數的具體用法?Golang ClientConfigFromFile怎麽用?Golang ClientConfigFromFile使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了ClientConfigFromFile函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: handlerToAnswer

func handlerToAnswer(w dns.ResponseWriter, r *dns.Msg) {
	db, err := sql.Open("mysql", "inserter:[email protected]/dnsServerCache") //Handler for database
	if err != nil {
		panic(err.Error()) // Just for example purpose. You should use proper error handling instead of panic
	}

	answer := new(dns.Msg) //Set answer to client
	answer.SetReply(r)     //Set reply flag and start collecting data for reply
	var answersAll []dns.RR
	answersAll = dbRespond(db, r.Question[0].String())
	if len(answersAll) != 0 {
		for _, answers := range answersAll {
			answer.Answer = append(answer.Answer, answers)
		}
	} else {
		client := new(dns.Client)
		var err1 error
		config, _ := dns.ClientConfigFromFile("/etc/resolv.conf")
		answer, _, err1 = client.Exchange(r, config.Servers[0]+":"+config.Port)
		if err1 != nil {
			panic(err1.Error())
		}
		if r.Rcode != dns.RcodeSuccess {
			return
		}
		go dbWriter(answer.Answer, db, r.Question[0].String())
	}
	w.WriteMsg(answer)
}
開發者ID:Shadowmad,項目名稱:Go-DNS-Server-with-MySQL-caching,代碼行數:29,代碼來源:server.go

示例2: main

func main() {
	if len(os.Args) <= 1 {
		log.Printf("Usage: %s domain", os.Args[0])
		os.Exit(1)
	}

	config, _ := dns.ClientConfigFromFile("/etc/resolv.conf")
	c := new(dns.Client)

	m := new(dns.Msg)
	m.SetQuestion(dns.Fqdn(os.Args[1]), dns.TypeMX)
	m.RecursionDesired = true

	r, _, err := c.Exchange(m, net.JoinHostPort(config.Servers[0], config.Port))
	if r == nil {
		log.Fatalf("*** error: %s\n", err.Error())
	}

	if r.Rcode != dns.RcodeSuccess {
		log.Fatalf(" *** invalid answer name %s after MX query for %s\n", os.Args[1], os.Args[1])
	}
	// Stuff must be in the answer section
	for _, a := range r.Answer {
		fmt.Printf("%v\n", a)
	}
}
開發者ID:soarpenguin,項目名稱:go-scripts,代碼行數:26,代碼來源:dnsUsage.go

示例3: lookupSRV

func lookupSRV(name string) (*dns.Msg, error) {
	conf, err := dns.ClientConfigFromFile(resolvConf)
	if err != nil {
		return nil, fmt.Errorf("Couldn't load resolv.conf: %s", err)
	}

	client := &dns.Client{}
	response := &dns.Msg{}

	for _, server := range conf.Servers {
		servAddr := net.JoinHostPort(server, conf.Port)
		for _, suffix := range conf.Search {
			response, err = lookup(name, dns.TypeSRV, client, servAddr, suffix, false)
			if err == nil {
				if len(response.Answer) > 0 {
					return response, nil
				}
			} else {
				glog.Warningf("Resolving %s.%s failed: %s", name, suffix, err)
			}
		}
		response, err = lookup(name, dns.TypeSRV, client, servAddr, "", false)
		if err == nil {
			return response, nil
		}
	}
	return response, fmt.Errorf("Couldn't resolve %s: No server responded", name)
}
開發者ID:pjjw,項目名稱:prometheus,代碼行數:28,代碼來源:target_provider.go

示例4: Config

func (u *upstream) Config() (*dns.ClientConfig, error) {
	u.Lock()
	defer u.Unlock()

	// If we checked less than five seconds ago return what we already have
	now := time.Now()
	if now.Sub(u.lastStat) < 5*time.Second {
		return u.cachedConfig, nil
	}
	u.lastStat = now

	// Reread file if it has changed
	if fi, err := os.Stat(u.resolvConf); err != nil {
		return u.cachedConfig, err
	} else if fi.ModTime() != u.lastModified {
		if config, err := dns.ClientConfigFromFile(u.resolvConf); err == nil {
			config.Servers = filter(config.Servers, u.filterAddress)
			u.lastModified = fi.ModTime()
			u.cachedConfig = config
		} else {
			return u.cachedConfig, err
		}
	}

	return u.cachedConfig, nil
}
開發者ID:n054,項目名稱:weave,代碼行數:26,代碼來源:dns.go

示例5: init

func init() {
	conf, err := dns.ClientConfigFromFile("/etc/resolv.conf")
	if err != nil || len(conf.Servers) == 0 {
		return
	}
	DefaultResolve = strings.Join(conf.Servers, ",")
}
開發者ID:senthilkungumaraj,項目名稱:dnsp,代碼行數:7,代碼來源:resolve_conf.go

示例6: loadRootConfig

func loadRootConfig() (err error) {
	rootConfig, err = dns.ClientConfigFromFile("/etc/resolv.conf")
	if err != nil {
		return err
	}
	return nil
}
開發者ID:bgentry,項目名稱:hk-check-dns,代碼行數:7,代碼來源:dns.go

示例7: NewDefaultLookupLib

func NewDefaultLookupLib() *LookupLib {
	config, _ := dns.ClientConfigFromFile("/etc/resolv.conf")
	serverString := config.Servers[0] + ":" + config.Port
	l := new(LookupLib)
	l.serverString = serverString
	return l
}
開發者ID:benbooth493,項目名稱:dns-clb-go,代碼行數:7,代碼來源:lib.go

示例8: localNameservers

// localNameservers returns list of local nameservers.
func localNameservers() ([]string, error) {
	c, err := dns.ClientConfigFromFile("/etc/resolv.conf")
	if err != nil {
		return nil, err
	}
	return c.Servers, nil
}
開發者ID:thinkingo,項目名稱:wagl,代碼行數:8,代碼來源:util.go

示例9: ResolvConf

func ResolvConf(config *Config, ctx *cli.Context) error {
	// Get host resolv config
	resolvConf, err := dns.ClientConfigFromFile("/etc/resolv.conf")
	if err != nil {
		return err
	}

	if len(config.Nameservers) == 0 {
		for _, s := range resolvConf.Servers {
			config.Nameservers = append(config.Nameservers, net.JoinHostPort(s, resolvConf.Port))
		}
	}

	if !ctx.IsSet("ndots") && resolvConf.Ndots != 1 {
		log.Debugf("Setting ndots from resolv.conf: %d", resolvConf.Ndots)
		config.Ndots = resolvConf.Ndots
	}

	if config.EnableSearch && len(config.SearchDomains) == 0 {
		for _, s := range resolvConf.Search {
			s = dns.Fqdn(strings.ToLower(s))
			config.SearchDomains = append(config.SearchDomains, s)
		}
	}

	return nil
}
開發者ID:janeczku,項目名稱:go-dnsmasq,代碼行數:27,代碼來源:config.go

示例10: NewDefaultResolver

func NewDefaultResolver() *Resolver {
	config, _ := dns.ClientConfigFromFile("/etc/resolv.conf")
	serverString := config.Servers[0] + ":" + config.Port
	l := new(Resolver)
	l.serverString = serverString
	return l
}
開發者ID:erdbehrmund,項目名稱:docker-volume-netshare,代碼行數:7,代碼來源:efs_resolve.go

示例11: Init

func Init() {
	var el error
	cf, el = dns.ClientConfigFromFile(DEFAULT_RESOLV_FILE)
	if el != nil {
		fmt.Println("DEFAULT_RESOLV_FILE ERR")
	}
}
開發者ID:yanzi1225627,項目名稱:HttpDNSServer,代碼行數:7,代碼來源:ednsManager.go

示例12: lookupAll

func lookupAll(name string, qtype uint16) (*dns.Msg, error) {
	conf, err := dns.ClientConfigFromFile(resolvConf)
	if err != nil {
		return nil, fmt.Errorf("could not load resolv.conf: %s", err)
	}

	client := &dns.Client{}
	response := &dns.Msg{}

	for _, server := range conf.Servers {
		servAddr := net.JoinHostPort(server, conf.Port)
		for _, suffix := range conf.Search {
			response, err = lookup(name, qtype, client, servAddr, suffix, false)
			if err != nil {
				log.Warnf("resolving %s.%s failed: %s", name, suffix, err)
				continue
			}
			if len(response.Answer) > 0 {
				return response, nil
			}
		}
		response, err = lookup(name, qtype, client, servAddr, "", false)
		if err == nil {
			return response, nil
		}
	}
	return response, fmt.Errorf("could not resolve %s: No server responded", name)
}
開發者ID:robbiet480,項目名稱:prometheus,代碼行數:28,代碼來源:dns.go

示例13: main

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

	m := new(dns.Msg)
	m.Question = make([]dns.Question, 1)
	c := new(dns.Client)

	addr := addresses(conf, c, os.Args[1])
	if len(addr) == 0 {
		fmt.Printf("No address found for %s\n", os.Args[1])
		os.Exit(1)
	}
	for _, a := range addr {
		m.Question[0] = dns.Question{"version.bind.", dns.TypeTXT, dns.ClassCHAOS}
		in, rtt, _ := c.ExchangeRtt(m, a)
		if in != nil && len(in.Answer) > 0 {
			fmt.Printf("(time %.3d µs) %v\n", rtt/1e3, in.Answer[0])
		}
		m.Question[0] = dns.Question{"hostname.bind.", dns.TypeTXT, dns.ClassCHAOS}
		in, rtt, _ = c.ExchangeRtt(m, a)
		if in != nil && len(in.Answer) > 0 {
			fmt.Printf("(time %.3d µs) %v\n", rtt/1e3, in.Answer[0])
		}
	}
}
開發者ID:polvi,項目名稱:dns,代碼行數:29,代碼來源:chaos.go

示例14: loadConfig

func loadConfig() error {
	loadConfigOnce.Do(func() {
		clientConfig, configLoadError = dns.ClientConfigFromFile("/etc/resolv.conf")
	})

	return configLoadError
}
開發者ID:hlandau,項目名稱:degoutils,代碼行數:7,代碼來源:resolver.go

示例15: getDNSServerAddress

func getDNSServerAddress() (string, error) {
	conf, err := dns.ClientConfigFromFile("/etc/resolv.conf")
	if err != nil {
		return "", fmt.Errorf("failed to load DNS config from /etc/resolv.conf: %v", err)
	}
	return net.JoinHostPort(conf.Servers[0], conf.Port), nil
}
開發者ID:nymsio,項目名稱:nyms-verifier,代碼行數:7,代碼來源:mail.go


注:本文中的github.com/miekg/dns.ClientConfigFromFile函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。