Looking up IP addresses from a hostname

The following example takes a hostname and returns the IP address. It is very similar to the previous example, but it is in reverse. The net.LookupHost() function does the heavy lifting:

package mainimport (   "fmt"   "log"   "net"   "os")func main() {   if len(os.Args) != 2 {      log.Fatal("No hostname argument provided.")   }   arg := os.Args[1]
     fmt.Println("Looking up IP addresses for hostname: " + arg)      ips, err := net.LookupHost(arg)   if err != nil {      log.Fatal(err)   }   for _, ip := range ips {      fmt.Println(ip)   }}

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.