Skip to content

Instantly share code, notes, and snippets.

@moloch--
Last active July 12, 2019 18:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moloch--/1bf9cb6cd05bb0e705904ea7b965efb6 to your computer and use it in GitHub Desktop.
Save moloch--/1bf9cb6cd05bb0e705904ea7b965efb6 to your computer and use it in GitHub Desktop.
func dnsTCPLookup(resolverIP string, domain string) (string, error) {
tcpResolver := net.Resolver{
PreferGo: true,
Dial: func(ctx context.Context, network, address string) (net.Conn, error) {
dialer := net.Dialer{}
return dialer.DialContext(ctx, "tcp", fmt.Sprintf("%s:53", resolverIP))
},
}
log.Printf("[dns] lookup -> %s", domain)
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
txts, err := tcpResolver.LookupTXT(ctx, domain)
if err != nil || len(txts) == 0 {
log.Printf("[!] failure -> %s", domain)
return "", err
}
return strings.Join(txts, ""), nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment