-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
64 lines (52 loc) · 1011 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main
import (
"flag"
"fmt"
"log"
"math/rand"
"os"
"strings"
"time"
"github.com/miekg/dns"
"github.com/vitalie/resolv"
"golang.org/x/net/context"
)
func usage() {
fmt.Fprintf(os.Stderr, "usage: lookup <domain> <type>\n")
flag.PrintDefaults()
os.Exit(2)
}
var debug bool
func main() {
rand.Seed(time.Now().UnixNano())
flag.BoolVar(&debug, "debug", false, "Enable debug messages")
flag.Usage = usage
flag.Parse()
args := flag.Args()
if len(args) < 1 {
fmt.Println("Name is missing.")
os.Exit(1)
}
qname := args[0]
qtype := dns.TypeA
if len(args) == 2 {
s := strings.ToUpper(args[1])
if v, ok := dns.StringToType[s]; ok {
qtype = v
} else {
fmt.Println("Invalid type:", s, ".")
os.Exit(1)
}
}
rs := resolv.NewResolver()
it := resolv.NewIterator(rs)
it.Debug = debug
ctx := context.Background()
for r := range it.Resolve(ctx, qname, qtype) {
if r.Err != nil {
log.Fatalln(r.Err)
}
fmt.Println("=====>", r.Addr)
fmt.Println(r.Msg)
}
}