-
-
Save moloch--/7ffa9548b3c0f826b39533fcde7e1105 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"context" | |
"fmt" | |
"net" | |
"os" | |
"time" | |
) | |
func main() { | |
resolver := &net.Resolver{ | |
PreferGo: true, | |
Dial: func(ctx context.Context, network, address string) (net.Conn, error) { | |
dialer := net.Dialer{Timeout: time.Duration(10 * time.Second)} | |
return dialer.DialContext(ctx, network, address) | |
}, | |
} | |
started := time.Now() | |
resolver.LookupIPAddr(context.Background(), os.Args[1]) | |
fmt.Printf("Query took: %s", time.Since(started)) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
➜ dnstest go build -o main main.go | |
➜ dnstest set -lx GODEBUG netdns=9 | |
➜ dnstest ./main google.com | |
go package net: using cgo DNS resolver | |
go package net: hostLookupOrder(google.com) = files,dns | |
Query took: 5.029126188s⏎ ➜ dnstest dig google.com | |
; <<>> DiG 9.10.6 <<>> google.com | |
;; global options: +cmd | |
;; Got answer: | |
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 16595 | |
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1 | |
;; OPT PSEUDOSECTION: | |
; EDNS: version: 0, flags:; udp: 1280 | |
;; QUESTION SECTION: | |
;google.com. IN A | |
;; ANSWER SECTION: | |
google.com. 155 IN A 172.217.4.46 | |
;; Query time: 12 msec | |
;; SERVER: 192.168.1.1#53(192.168.1.1) | |
;; WHEN: Sun Oct 31 16:18:57 CDT 2021 | |
;; MSG SIZE rcvd: 55 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment