本文整理匯總了Golang中github.com/miekg/dns.Fqdn函數的典型用法代碼示例。如果您正苦於以下問題:Golang Fqdn函數的具體用法?Golang Fqdn怎麽用?Golang Fqdn使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Fqdn函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: newRR
func newRR(q dns.Question, i instance) dns.RR {
hdr := dns.RR_Header{
Name: q.Name,
Rrtype: q.Qtype,
Class: dns.ClassINET,
Ttl: defaultTTL,
}
switch q.Qtype {
case dns.TypeA:
return &dns.A{
Hdr: hdr,
A: i.ip,
}
case dns.TypeSRV:
return &dns.SRV{
Hdr: hdr,
Priority: 0,
Weight: 0,
Port: i.port,
Target: dns.Fqdn(i.host),
}
case dns.TypeNS:
return &dns.NS{
Hdr: hdr,
Ns: dns.Fqdn(i.host),
}
default:
panic("unreachable")
}
}
示例2: RRs
func (v *Value) RRs(out []dns.RR, suffix, apexSuffix string) ([]dns.RR, error) {
il := len(out)
suffix = dns.Fqdn(suffix)
apexSuffix = dns.Fqdn(apexSuffix)
out, _ = v.appendNSs(out, suffix, apexSuffix)
if len(v.NS) == 0 {
out, _ = v.appendTranslate(out, suffix, apexSuffix)
if !v.HasTranslate {
out, _ = v.appendAlias(out, suffix, apexSuffix)
if !v.HasAlias {
out, _ = v.appendIPs(out, suffix, apexSuffix)
out, _ = v.appendIP6s(out, suffix, apexSuffix)
out, _ = v.appendTXTs(out, suffix, apexSuffix)
out, _ = v.appendMXs(out, suffix, apexSuffix)
out, _ = v.appendSRVs(out, suffix, apexSuffix)
out, _ = v.appendTLSA(out, suffix, apexSuffix)
}
}
}
out, _ = v.appendDSs(out, suffix, apexSuffix)
xout := out[il:]
for i := range xout {
h := xout[i].Header()
if rrtypeHasPrefix(h.Rrtype) {
h.Name += suffix
} else {
h.Name = suffix
}
}
return out, nil
}
示例3: Init
func (r *RFC2136Provider) Init(rootDomainName string) error {
var host, port, keyName, secret string
if host = os.Getenv("RFC2136_HOST"); len(host) == 0 {
return fmt.Errorf("RFC2136_HOST is not set")
}
if port = os.Getenv("RFC2136_PORT"); len(port) == 0 {
return fmt.Errorf("RFC2136_PORT is not set")
}
if keyName = os.Getenv("RFC2136_TSIG_KEYNAME"); len(keyName) == 0 {
return fmt.Errorf("RFC2136_TSIG_KEYNAME is not set")
}
if secret = os.Getenv("RFC2136_TSIG_SECRET"); len(secret) == 0 {
return fmt.Errorf("RFC2136_TSIG_SECRET is not set")
}
r.nameserver = net.JoinHostPort(host, port)
r.zoneName = dns.Fqdn(rootDomainName)
r.tsigKeyName = dns.Fqdn(keyName)
r.tsigSecret = secret
logrus.Infof("Configured %s with zone '%s' and nameserver '%s'",
r.GetName(), r.zoneName, r.nameserver)
return nil
}
示例4: addresses
func addresses(conf *dns.ClientConfig, c *dns.Client, name string) []string {
m4 := new(dns.Msg)
m4.SetQuestion(dns.Fqdn(os.Args[1]), dns.TypeA)
m6 := new(dns.Msg)
m6.SetQuestion(dns.Fqdn(os.Args[1]), dns.TypeAAAA)
addr := make(chan []string)
defer close(addr)
c.Do(m4, conf.Servers[0]+":"+conf.Port, addr, qhandler)
c.Do(m6, conf.Servers[0]+":"+conf.Port, addr, qhandler)
var ips []string
i := 2 // two outstanding queries
forever:
for {
select {
case ip := <-addr:
ips = append(ips, ip...)
i--
if i == 0 {
break forever
}
}
}
return ips
}
示例5: VerifyTargetHandler
func VerifyTargetHandler(w http.ResponseWriter, req *http.Request) {
if !checkAuth(req, authuser, authpassword) {
UnauthorizedResponse(w)
return
}
hostname1 := dns.Fqdn(mux.Vars(req)["hostname1"])
hostname2 := dns.Fqdn(mux.Vars(req)["hostname2"])
nocache := req.URL.Query().Get("nocache") != ""
target_alias := req.URL.Query().Get("target_alias")
if target_alias != "" {
target_alias = dns.Fqdn(target_alias)
}
vr, err := VerifyTarget(hostname1, hostname2, target_alias, nocache)
if err != nil {
w.WriteHeader(500)
json.NewEncoder(w).Encode(vr.Error)
return
}
json.NewEncoder(w).Encode(vr)
return
}
示例6: discoverDNS
func discoverDNS(domain string, port int) (servers []string, ttl time.Duration, err error) {
r, _ := region()
// all DNS queries must use the FQDN
domain = "txt." + r + "." + dns.Fqdn(domain)
if _, ok := dns.IsDomainName(domain); !ok {
err = fmt.Errorf("invalid domain name: '%s' is not a domain name", domain)
return
}
regionRecords, ttl, err := retryingFindTXT(domain)
if err != nil {
return
}
for _, az := range regionRecords {
instances, _, er := retryingFindTXT("txt." + dns.Fqdn(az))
if er != nil {
continue
}
for _, instance := range instances {
// format the service URL
servers = append(servers, fmt.Sprintf("http://%s:%d/eureka/v2", instance, port))
}
}
return
}
示例7: lookupIPs
func (c *Client) lookupIPs(host string) (ips []net.IP, err error) {
m := new(dns.Msg)
for _, resolver := range c.Resolvers {
m.SetQuestion(dns.Fqdn(host), dns.TypeA)
if in, err := dns.Exchange(m, resolver); err == nil {
for _, rr := range in.Answer {
if a, ok := rr.(*dns.A); ok {
ips = append(ips, a.A)
}
}
} else {
log.Debug(err)
}
m.SetQuestion(dns.Fqdn(host), dns.TypeAAAA)
if in, err := dns.Exchange(m, resolver); err == nil {
for _, rr := range in.Answer {
if aaaa, ok := rr.(*dns.AAAA); ok {
ips = append(ips, aaaa.AAAA)
}
}
} else {
log.Debug(err)
}
}
if len(ips) != 0 {
return ips, nil
}
return net.LookupIP(host)
}
示例8: ParseSOA
func ParseSOA(d string, r []dns.RR) (*dns.SOA, []*dns.NS, *MyError.MyError) {
var soa *dns.SOA
var ns_a []*dns.NS
for _, v := range r {
vh := v.Header()
if vh.Name == dns.Fqdn(d) || dns.IsSubDomain(vh.Name, dns.Fqdn(d)) {
switch vh.Rrtype {
case dns.TypeSOA:
if vv, ok := v.(*dns.SOA); ok {
//fmt.Print(utils.GetDebugLine(), "ParseSOA: ", vv)
soa = vv
utils.ServerLogger.Debug("ParseSOA: %v", vv)
}
case dns.TypeNS:
if vv, ok := v.(*dns.NS); ok {
ns_a = append(ns_a, vv)
}
default:
//fmt.Println(utils.GetDebugLine(), " PasreSOA: error unexpect: ", v)
utils.ServerLogger.Error("ParseSOA: error unexpect %v", v)
}
} else {
//fmt.Print(utils.GetDebugLine(), "ParseSOA 258 ")
//fmt.Println(utils.GetDebugLine(), vh.Name+" not match "+d)
utils.ServerLogger.Debug("%s not match %s", vh.Name, d)
return nil, nil, MyError.NewError(MyError.ERROR_NOTVALID, d+" has no SOA record,try parent")
}
}
if soa != nil {
return soa, ns_a, nil
} else {
return nil, nil, MyError.NewError(MyError.ERROR_NORESULT, "No SOA record for domain "+d)
}
}
示例9: Resolve
// Get IP addresses related to the given local hostname
func (m *mdns) Resolve(host string) []net.IP {
results := make(chan dns.RR)
m.queries <- &query{
questions: []dns.Question{
dns.Question{dns.Fqdn(host), dns.TypeA, dns.ClassINET},
dns.Question{dns.Fqdn(host), dns.TypeAAAA, dns.ClassINET},
},
results: results,
}
ipset := map[string]net.IP{}
ips := []net.IP{}
for rr := range results {
var ip net.IP
switch rr := rr.(type) {
case *dns.A:
ip = rr.A
case *dns.AAAA:
ip = make([]byte, 16)
copy(ip, rr.AAAA[:])
default:
continue
}
if _, ok := ipset[ip.String()]; !ok {
ipset[ip.String()] = ip
ips = append(ips, ip)
}
}
return ips
}
示例10: UpdateAlias
func (s *Service) UpdateAlias(zone string, ttl uint32, from, to *Device) error {
for _, r := range from.Aliases {
if to.HasAlias(r) {
continue
}
fmt.Printf("EXTRA ALIAS: %s\n", r)
cname := &dns.CNAME{
Hdr: dns.RR_Header{Name: dns.Fqdn(r), Rrtype: dns.TypeCNAME, Class: dns.ClassINET},
Target: dns.Fqdn(to.Name),
}
fmt.Println(cname)
if err := s.RemoveRRset(zone, []dns.RR{cname}); err != nil {
return err
}
}
for _, r := range to.Aliases {
if from.HasAlias(r) {
continue
}
fmt.Printf("MISSING ALIAS: %s\n", r)
cname := &dns.CNAME{
Hdr: dns.RR_Header{Name: dns.Fqdn(r), Rrtype: dns.TypeCNAME, Class: dns.ClassINET},
Target: dns.Fqdn(from.Name),
}
fmt.Println(cname)
if err := s.RemoveRRset(zone, []dns.RR{cname}); err != nil {
return err
}
if err := s.Insert(zone, []dns.RR{cname}); err != nil {
return err
}
}
return nil
}
示例11: RemoveName
// Dynamically remove a full set of RR records stored in DNS
func (s *Service) RemoveName(zone string, rr []dns.RR) error {
m := new(dns.Msg)
m.SetUpdate(zone)
m.SetTsig(dns.Fqdn(s.Key), dns.HmacMD5, 300, time.Now().Unix())
m.RemoveName(rr)
h, err := s.ServerPort()
if err != nil {
return err
}
c := new(dns.Client)
c.TsigSecret = map[string]string{dns.Fqdn(s.Key): s.Secret}
r, _, err := c.Exchange(m, h)
if err != nil {
return err
}
if r.Rcode != dns.RcodeSuccess {
return errors.New(fmt.Sprintf("invalid exchange answer"))
}
return nil
}
示例12: Addresses
func (answers *Answers) Addresses(clientIp string, fqdn string, cnameParents []dns.RR, depth int) (records []dns.RR, ok bool) {
fqdn = dns.Fqdn(fqdn)
log.WithFields(log.Fields{"fqdn": fqdn, "client": clientIp, "depth": depth}).Debug("Trying to resolve addresses")
// Limit recursing for non-obvious loops
if len(cnameParents) >= 10 {
log.WithFields(log.Fields{"fqdn": fqdn, "client": clientIp}).Warn("Followed CNAME too many times ", cnameParents)
return nil, false
}
// Look for a CNAME entry
result, ok := answers.Matching(dns.TypeCNAME, clientIp, fqdn)
if ok && len(result) > 0 {
cname := result[0].(*dns.CNAME)
log.WithFields(log.Fields{"fqdn": fqdn, "client": clientIp}).Debug("Matched CNAME ", cname.Target)
// Stop obvious loops
if dns.Fqdn(cname.Target) == fqdn {
log.WithFields(log.Fields{"fqdn": fqdn, "client": clientIp}).Warn("CNAME is a loop ", cname.Target)
return nil, false
}
// Recurse to find the eventual A for this CNAME
children, ok := answers.Addresses(clientIp, dns.Fqdn(cname.Target), append(cnameParents, cname), depth+1)
if ok && len(children) > 0 {
log.WithFields(log.Fields{"fqdn": fqdn, "target": cname.Target, "client": clientIp}).Debug("Resolved CNAME ", children)
records = append(records, cname)
records = append(records, children...)
return records, true
}
}
// Look for an A entry
result, ok = answers.Matching(dns.TypeA, clientIp, fqdn)
if ok && len(result) > 0 {
log.WithFields(log.Fields{"fqdn": fqdn, "client": clientIp}).Debug("Matched A ", result)
shuffle(&result)
return result, true
}
// Try the default section of the config
if clientIp != DEFAULT_KEY {
return answers.Addresses(DEFAULT_KEY, fqdn, cnameParents, depth+1)
}
// When resolving CNAMES, check recursive server
if len(cnameParents) > 0 {
log.WithFields(log.Fields{"fqdn": fqdn, "client": clientIp}).Debug("Trying recursive servers")
r := new(dns.Msg)
r.SetQuestion(fqdn, dns.TypeA)
msg, err := ResolveTryAll(r, answers.Recursers(clientIp))
if err == nil {
return msg.Answer, true
}
}
log.WithFields(log.Fields{"fqdn": fqdn, "client": clientIp}).Debug("Did not match anything")
return nil, false
}
示例13: lookupHost
func lookupHost(host string, config *dns.ClientConfig) (addrs []string, err error) {
if utilNet.IsValidIpv4(host) || utilNet.IsValidIpv6(host) {
return []string{host}, nil
}
if host == "localhost" {
return []string{"127.0.0.1", "::1"}, nil
}
c := new(dns.Client)
c.DialTimeout = DialTimeout
c.ReadTimeout = ReadTimeout
c.WriteTimeout = WriteTimeout
m := new(dns.Msg)
m.SetQuestion(dns.Fqdn(host), dns.TypeA)
var r *dns.Msg
for i := 0; i < len(config.Servers); i++ {
r, _, err = c.Exchange(m, config.Servers[i]+":"+config.Port)
if err != nil {
continue
}
err = nil
}
if err != nil {
return nil, e.Forward(err)
}
if r.Rcode != dns.RcodeSuccess {
return nil, e.New("can't resolve %v", host)
}
addrs = make([]string, 0, 10)
for _, a := range r.Answer {
if addr, ok := a.(*dns.A); ok {
addrs = append(addrs, addr.A.String())
}
}
m.SetQuestion(dns.Fqdn(host), dns.TypeAAAA)
for i := 0; i < len(config.Servers); i++ {
r, _, err = c.Exchange(m, config.Servers[0]+":"+config.Port)
if err != nil {
continue
}
err = nil
}
if err != nil {
return nil, e.Forward(err)
}
if r.Rcode != dns.RcodeSuccess {
return nil, e.New("no success")
}
for _, a := range r.Answer {
if addr, ok := a.(*dns.AAAA); ok {
addrs = append(addrs, addr.AAAA.String())
}
}
return
}
示例14: InWhiteList
//todo: complete this func
func InWhiteList(d string) bool {
d = dns.Fqdn(d)
for _, x := range RC.Domains {
if d == dns.Fqdn(x) {
return true
}
}
return false
}
示例15: dnsCNAME
// dnsCNAME returns a DNS CNAME record struct
func dnsCNAME(src, dest string) *dns.CNAME {
return &dns.CNAME{
Hdr: dns.RR_Header{
Name: dns.Fqdn(src),
Rrtype: dns.TypeCNAME,
Class: dns.ClassINET,
},
Target: dns.Fqdn(dest),
}
}