mirror of
https://github.com/tailscale/tailscale.git
synced 2024-12-12 03:04:40 +00:00
da8def8e13
The //go:build syntax was introduced in Go 1.17: https://go.dev/doc/go1.17#build-lines gofmt has kept the +build and go:build lines in sync since then, but enough time has passed. Time to remove them. Done with: perl -i -npe 's,^// \+build.*\n,,' $(git grep -l -F '+build') Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
56 lines
1.1 KiB
Go
56 lines
1.1 KiB
Go
// Copyright (c) 2021 Tailscale Inc & AUTHORS All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
//go:build ignore
|
|
|
|
// Command dns_tester exists in order to perform tests of our DNS
|
|
// configuration stack. This was written because the state of DNS
|
|
// in our target environments is so diverse that we need a little tool
|
|
// to do this test for us.
|
|
package main
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"flag"
|
|
"net"
|
|
"os"
|
|
"time"
|
|
)
|
|
|
|
func main() {
|
|
flag.Parse()
|
|
target := flag.Arg(0)
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
defer cancel()
|
|
|
|
errCount := 0
|
|
wait := 25 * time.Millisecond
|
|
for range make([]struct{}, 5) {
|
|
err := lookup(ctx, target)
|
|
if err != nil {
|
|
errCount++
|
|
time.Sleep(wait)
|
|
wait = wait * 2
|
|
continue
|
|
}
|
|
|
|
break
|
|
}
|
|
}
|
|
|
|
func lookup(ctx context.Context, target string) error {
|
|
ctx, cancel := context.WithTimeout(ctx, time.Second)
|
|
defer cancel()
|
|
|
|
hosts, err := net.LookupHost(target)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
json.NewEncoder(os.Stdout).Encode(hosts)
|
|
return nil
|
|
}
|