本文整理匯總了Golang中github.com/miekg/dns.Transfer.In方法的典型用法代碼示例。如果您正苦於以下問題:Golang Transfer.In方法的具體用法?Golang Transfer.In怎麽用?Golang Transfer.In使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/miekg/dns.Transfer
的用法示例。
在下文中一共展示了Transfer.In方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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
}
示例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)
}
示例3: 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
}
示例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
}
示例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
}
示例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
}
示例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()
}
示例8: main
func main() {
short = flag.Bool("short", false, "abbreviate long DNSSEC records")
dnssec := flag.Bool("dnssec", false, "request DNSSEC records")
query := flag.Bool("question", false, "show question")
check := flag.Bool("check", false, "check internal DNSSEC consistency")
six := flag.Bool("6", false, "use IPv6 only")
four := flag.Bool("4", false, "use IPv4 only")
anchor := flag.String("anchor", "", "use the DNSKEY in this file as trust anchor")
tsig := flag.String("tsig", "", "request tsig with key: [hmac:]name:key")
port := flag.Int("port", 53, "port number to use")
aa := flag.Bool("aa", false, "set AA flag in query")
ad := flag.Bool("ad", false, "set AD flag in query")
cd := flag.Bool("cd", false, "set CD flag in query")
rd := flag.Bool("rd", true, "set RD flag in query")
fallback := flag.Bool("fallback", false, "fallback to 4096 bytes bufsize and after that TCP")
tcp := flag.Bool("tcp", false, "TCP mode, multiple queries are asked over the same connection")
nsid := flag.Bool("nsid", false, "set edns nsid option")
client := flag.String("client", "", "set edns client-subnet option")
clientdraftcode := flag.Bool("clientdraft", false, "set edns client-subnet option using the draft option code")
opcode := flag.String("opcode", "query", "set opcode to query|update|notify")
rcode := flag.String("rcode", "success", "set rcode to noerror|formerr|nxdomain|servfail|...")
//serial := flag.Int("serial", 0, "perform an IXFR with this serial")
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "Usage: %s [options] [@server] [qtype...] [qclass...] [name ...]\n", os.Args[0])
flag.PrintDefaults()
}
var (
qtype []uint16
qclass []uint16
qname []string
)
flag.Parse()
if *anchor != "" {
f, err := os.Open(*anchor)
if err != nil {
fmt.Fprintf(os.Stderr, "Failure to open %s: %s\n", *anchor, err.Error())
}
r, err := dns.ReadRR(f, *anchor)
if err != nil {
fmt.Fprintf(os.Stderr, "Failure to read an RR from %s: %s\n", *anchor, err.Error())
}
if k, ok := r.(*dns.DNSKEY); !ok {
fmt.Fprintf(os.Stderr, "No DNSKEY read from %s\n", *anchor)
} else {
dnskey = k
}
}
var nameserver string
Flags:
for i := 0; i < flag.NArg(); i++ {
// If it starts with @ it is a nameserver
if flag.Arg(i)[0] == '@' {
nameserver = flag.Arg(i)
continue Flags
}
// First class, then type, to make ANY queries possible
// And if it looks like type, it is a type
if k, ok := dns.StringToType[strings.ToUpper(flag.Arg(i))]; ok {
qtype = append(qtype, k)
continue Flags
}
// If it looks like a class, it is a class
if k, ok := dns.StringToClass[strings.ToUpper(flag.Arg(i))]; ok {
qclass = append(qclass, k)
continue Flags
}
// If it starts with TYPExxx it is unknown rr
if strings.HasPrefix(flag.Arg(i), "TYPE") {
i, e := strconv.Atoi(string([]byte(flag.Arg(i))[4:]))
if e == nil {
qtype = append(qtype, uint16(i))
continue Flags
}
}
// If it starts with CLASSxxx it is unknown class
if strings.HasPrefix(flag.Arg(i), "CLASS") {
i, e := strconv.Atoi(string([]byte(flag.Arg(i))[5:]))
if e == nil {
qclass = append(qclass, uint16(i))
continue Flags
}
}
// Anything else is a qname
qname = append(qname, flag.Arg(i))
}
if len(qname) == 0 {
qname = []string{"."}
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)
//.........這裏部分代碼省略.........
示例9: 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
}