Ejemplo n.º 1
0
func main() {
	flag.Parse()
	if len(flag.Args()) != 1 {
		fmt.Println("usage: <hostname>")
		os.Exit(1)
	}

	u := unbound.New()
	defer u.Destroy()

	if err := u.ResolvConf("/etc/resolv.conf"); err != nil {
		fmt.Printf("error reading resolv.conf %s\n", err.Error())
		os.Exit(1)
	}

	if err := u.Hosts("/etc/hosts"); err != nil {
		fmt.Printf("error reading hosts: %s\n", err.Error())
		os.Exit(1)
	}

	r, err := u.Resolve(flag.Arg(0), dns.TypeA, dns.ClassINET)
	if err != nil {
		fmt.Printf("resolve error %s\n", err.Error())
		os.Exit(1)
	}
	examineResult(flag.Arg(0), r)
}
Ejemplo n.º 2
0
func main() {
	u := unbound.New()
	defer u.Destroy()

	if err := u.ResolvConf("/etc/resolv.conf"); err != nil {
		log.Fatalf("error %s\n", err.Error())
	}

	if err := u.Hosts("/etc/hosts"); err != nil {
		log.Fatalf("error %s\n", err.Error())
	}

	if err := u.AddTaFile("keys"); err != nil {
		log.Fatalf("error %s\n", err.Error())
	}

	r, err := u.Resolve("nlnetlabs.nl.", dns.TypeA, dns.ClassINET)
	if err != nil {
		log.Fatalf("error %s\n", err.Error())
	}

	// show first result
	if r.HaveData {
		fmt.Printf("The address is %v\n", r.Data[0])
		// show security status
		if r.Secure {
			fmt.Printf("Result is secure\n")
		} else if r.Bogus {
			fmt.Printf("Result is bogus: %s\n", r.WhyBogus)
		} else {
			fmt.Printf("Result is insecure\n")
		}
	}
}
Ejemplo n.º 3
0
func main() {
	u := unbound.New()
	defer u.Destroy()
	done := make(chan *unbound.ResultError)

	if err := u.ResolvConf("/etc/resolv.conf"); err != nil {
		log.Fatalf("error %s\n", err.Error())
	}

	if err := u.Hosts("/etc/hosts"); err != nil {
		log.Fatalf("error %s\n", err.Error())
	}

	u.ResolveAsync("www.nlnetlabs.nl.", dns.TypeA, dns.ClassINET, done)
For:
	for {
		select {
		case r := <-done:
			if r.Error != nil {
				fmt.Printf("resolve error: %s\n", r.Error.Error())
				break For
			}
			if r.Result.HaveData {
				fmt.Printf("The address of %s is %v\n", r.Result.Qname, r.Result.Data[0])
				break For
			}

		}
	}
	fmt.Println("done")
}
Ejemplo n.º 4
0
func main() {
	u := unbound.New()
	defer u.Destroy()
	done := 0

	if err := u.ResolvConf("/etc/resolv.conf"); err != nil {
		fmt.Printf("error %s\n", err.Error())
		os.Exit(1)
	}

	if err := u.Hosts("/etc/hosts"); err != nil {
		fmt.Printf("error %s\n", err.Error())
		os.Exit(1)
	}

	err := u.ResolveAsync("www.nlnetlabs.nl.", dns.TypeA, dns.ClassINET, &done, mycallback)
	if err != nil { // Will not happen in Go's case, as the return code is always nil
		fmt.Printf("error %s\n", err.Error())
		os.Exit(1)
	}
	i := 0
	for done == 0 {
		time.Sleep(1e8) // wait 1/10 of a second
		fmt.Printf("time passed (%d) ..\n", i)
		i++
	}
	fmt.Println("done")
}
Ejemplo n.º 5
0
func main() {
	u := unbound.New()
	defer u.Destroy()

	u.ResolvConf("/etc/resolv.conf")
	a, err := u.LookupHost("www.nlnetlabs.nl")
	if err != nil {
		log.Fatalf("error %s\n", err.Error())
	}
	for _, a1 := range a {
		fmt.Printf("The address is %s\n", a1)
	}
}
Ejemplo n.º 6
0
func parseHandlerCSV(w http.ResponseWriter, r *http.Request) {
	lg.Printf("Upload request from %s\n", r.RemoteAddr)

	f, _, err := r.FormFile("domainlist")
	if err != nil {
		lg.Printf("Error opening CSV: %s\n", err.Error())
		fmt.Fprintf(w, "Error opening CSV: %s\n", err.Error())
		return
	}
	u := unbound.New()
	defer u.Destroy()
	setupUnbound(u)

	v := csv.NewReader(f)
	o := csv.NewWriter(w)
	record, err := v.Read()
	all := NewAllResults()
	i := 0
	if err != nil {
		lg.Printf("Malformed CSV: %s ", err.Error())
		fmt.Fprintf(w, "Malformed CSV: %s\n", err.Error())
		return

	}
Check:

	for err == nil {
		for _, r1 := range record {
			result := unboundcheck(u, r1, "NS")
			lg.Printf("%v from %s\n", result, r.RemoteAddr)
			all.Append(result)
			i++
			if i > LIMIT {
				// That's enough...!
				lg.Printf("limit seen")
				break Check
			}
		}
		record, err = v.Read()
	}
	sort.Sort(all)
	for _, r := range all.r {
		if e := o.Write(r.serialize()); e != nil {
			lg.Printf("Failed to write csv: %s\n", e.Error())
		}
		o.Flush()
	}
}
Ejemplo n.º 7
0
// ReST check
func checkHandler(w http.ResponseWriter, r *http.Request) {
	lg.Printf("RESTful request from %s\n", r.RemoteAddr)

	vars := mux.Vars(r)
	zone := vars["domain"]
	u := unbound.New()
	defer u.Destroy()
	setupUnbound(u)
	result := unboundcheck(u, zone, "A")
	o := csv.NewWriter(w)
	if e := o.Write(result.serialize()); e != nil {
		lg.Printf("Failed to write csv: %s\n", e.Error())
	}
	lg.Printf("%v from %s\n", result, r.RemoteAddr)
	o.Flush()
}
Ejemplo n.º 8
0
func main() {
	u := unbound.New()
	defer u.Destroy()

	if err := u.ResolvConf("/etc/resolv.conf"); err != nil {
		log.Fatalf("error %s\n", err.Error())
	}

	if err := u.Hosts("/etc/hosts"); err != nil {
		log.Fatalf("error %s\n", err.Error())
	}
	r, err := u.Resolve("www.nlnetlabs.nl.", dns.TypeA, dns.ClassINET)
	if err != nil {
		log.Fatalf("error %s\n", err.Error())
	}
	fmt.Printf("%+v\n", r)
}
Ejemplo n.º 9
0
func main() {
	u := unbound.New()
	defer u.Destroy()

	if err := u.ResolvConf("/etc/resolv.conf"); err != nil {
		log.Fatalf("error %s\n", err.Error())
	}

	if err := u.Hosts("/etc/hosts"); err != nil {
		log.Fatalf("error %s\n", err.Error())
	}
	q := make(chan bool)
	// start two goroutines
	go goroutineOne(u, q)
	go goroutineTwo(u, q)
	// wait for both routines to complete
	<-q
	<-q
}
Ejemplo n.º 10
0
// http://dns.bortzmeyer.org/{+domain}/{querytype}{?format,server,buffersize,dodnssec,tcp,reverse
func handler(w http.ResponseWriter, r *http.Request, typ string) {
	var (
		dnstype uint16
		ok      bool
	)
	lg.Printf("request from %s %s\n", r.RemoteAddr, r.URL)
	if dnstype, ok = dns.StringToType[typ]; !ok {
		fmt.Fprintf(w, "Record type "+typ+" does not exist")
		return
	}
	domain := mux.Vars(r)["domain"]
	domain = html.UnescapeString(domain)

	u := unbound.New()
	defer u.Destroy()
	forward := false
	format := "html"
	u.SetOption("module-config:", "iterator")
	for k, v := range r.URL.Query() {
		switch k {
		case "tcp":
			if v[0] == "1" {
				u.SetOption("tcp-upstream:", "yes")
			}
		case "dodnssec":
			if v[0] == "1" {
				u.SetOption("module-config:", "validator iterator")
				u.SetOption("edns-buffer-size:", "4096")
				u.AddTa(`;; ANSWER SECTION:
.                       168307 IN DNSKEY 257 3 8 (
                                AwEAAagAIKlVZrpC6Ia7gEzahOR+9W29euxhJhVVLOyQ
                                bSEW0O8gcCjFFVQUTf6v58fLjwBd0YI0EzrAcQqBGCzh
                                /RStIoO8g0NfnfL2MTJRkxoXbfDaUeVPQuYEhg37NZWA
                                JQ9VnMVDxP/VHL496M/QZxkjf5/Efucp2gaDX6RS6CXp
                                oY68LsvPVjR0ZSwzz1apAzvN9dlzEheX7ICJBBtuA6G3
                                LQpzW5hOA2hzCTMjJPJ8LbqF6dsV6DoBQzgul0sGIcGO
                                Yl7OyQdXfZ57relSQageu+ipAdTTJ25AsRTAoub8ONGc
                                LmqrAmRLKBP1dfwhYB4N7knNnulqQxA+Uk1ihz0=
                                ) ; key id = 19036`)
			}
		case "buffersize":
			if err := u.SetOption("edns-buffer-size:", v[0]); err != nil {
				fmt.Fprintf(w, "Not a valid buffer size: %s", v[0])
				return
			}
		case "server":
			if err := u.SetFwd(v[0]); err != nil {
				fmt.Fprintf(w, "Not a valid server `%s': %s", v[0], err.Error())
				return
			}
			forward = true
		case "reverse":
			if v[0] == "1" {
				var err error
				dnstype = dns.TypePTR
				domain, err = dns.ReverseAddr(domain)
				if err != nil {
					fmt.Fprintf(w, "Not a valid IP address: %s", v[0])
					return
				}
			}
		case "format": // unsupported format defaut to html
			for _, f := range []string{"html", "zone", "xml", "json", "text"} {
				if v[0] == f {
					format = f
				}
			}
		}
	}
	if !forward {
		u.ResolvConf("/etc/resolv.conf")
	}
	d, err := u.Resolve(domain, dnstype, dns.ClassINET)
	if err != nil {
		fmt.Fprintf(w, "error")
		return
	}
	if !d.HaveData {
		fmt.Fprintf(w, "Domain %s (type %s) does not exist", domain, dns.TypeToString[dnstype])
		return
	}
	switch format {
	case "json":
		Json(w, d)
	case "xml":
		Xml(w, d)
	case "html":
		fallthrough
	case "text":
		fallthrough
	case "zone":
		Zone(w, d)
	}
}
Ejemplo n.º 11
0
		"68.87.76.178",    // Comcast Los Angeles Primary
		"68.87.78.130",    // Comcast Los Angeles Secondary
		"68.87.69.146",    // Comcast Orgeon Primary
		"68.87.85.98",     // Comcast Orgeon Secondary
		"68.87.85.98",     // Comcast Utah Primary
		"68.87.69.146",    // Comcast Utah Secondary
	}}

	ch = make(chan Result, CONCURRENCY)

	// Preserve input line (if this is true then don't cleanup and reduce to just the domain name).
	preserveInput = false

	outputLock sync.Mutex

	unboundInstance = unbound.New()
)

func init() {
	unboundInstance.ResolvConf("/etc/resolv.conf")
}

// TODO: protect this region to be accessible by only 1 thread at a time.
func (this *DnsServerRing) next() string {
	if this.index < 0 || this.index+1 == len(this.servers) {
		this.index = 0
	} else {
		this.index++
	}
	return this.servers[this.index]
}