Looking up nameservers for a hostname

This program will find nameservers associated with a given hostname. The primary function here is net.LookupNS():

package mainimport (   "fmt"   "log"   "net"   "os")func main() {   if len(os.Args) != 2 {      log.Fatal("No domain name argument provided")   }   arg := os.Args[1]     fmt.Println("Looking up nameservers for " + arg)    nameservers, err := net.LookupNS(arg)   if err != nil {      log.Fatal(err)   }   for _, nameserver := range nameservers {      fmt.Println(nameserver.Host)   }}

Get Security with Go now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.