|
| 1 | +package main |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "net" |
| 6 | + "strings" |
| 7 | +) |
| 8 | + |
| 9 | +const myResolverHost string = "resolver.dnscrypt.info" |
| 10 | + |
| 11 | +func Resolve(name string) { |
| 12 | + fmt.Printf("Resolving [%s]\n\n", name) |
| 13 | + |
| 14 | + fmt.Printf("Domain exists: ") |
| 15 | + ns, err := net.LookupNS(name) |
| 16 | + if err != nil || len(ns) == 0 { |
| 17 | + if name == "." { |
| 18 | + fmt.Println("'No' would mean that the Internet doesn't exist any more, and that would be very sad. On the bright side, you just found an easter egg.") |
| 19 | + } else { |
| 20 | + fmt.Println("probably not, or blocked by the proxy") |
| 21 | + } |
| 22 | + } else { |
| 23 | + fmt.Printf("yes, %d name servers found\n", len(ns)) |
| 24 | + } |
| 25 | + |
| 26 | + fmt.Printf("Canonical name: ") |
| 27 | + cname, err := net.LookupCNAME(name) |
| 28 | + if err != nil { |
| 29 | + fmt.Println("-") |
| 30 | + } else { |
| 31 | + fmt.Println(cname) |
| 32 | + } |
| 33 | + |
| 34 | + fmt.Printf("IP addresses: ") |
| 35 | + addrs, err := net.LookupHost(name) |
| 36 | + if err != nil { |
| 37 | + fmt.Println("-") |
| 38 | + } else { |
| 39 | + fmt.Println(strings.Join(addrs, ", ")) |
| 40 | + } |
| 41 | + |
| 42 | + fmt.Printf("TXT records: ") |
| 43 | + txt, err := net.LookupTXT(name) |
| 44 | + if err != nil { |
| 45 | + fmt.Println("-") |
| 46 | + } else { |
| 47 | + fmt.Println(strings.Join(txt, " ")) |
| 48 | + } |
| 49 | + |
| 50 | + resIP, err := net.LookupHost(myResolverHost) |
| 51 | + if err == nil && len(resIP) > 0 { |
| 52 | + fmt.Printf("Resolver IP: %s", resIP[0]) |
| 53 | + rev, err := net.LookupAddr(resIP[0]) |
| 54 | + if err == nil && len(rev) > 0 { |
| 55 | + fmt.Printf(" (%s)", rev[0]) |
| 56 | + } |
| 57 | + fmt.Println("") |
| 58 | + } |
| 59 | + fmt.Println("") |
| 60 | +} |
0 commit comments