Looking up a hostname from an IP address

This program will take an IP address and figure out what the hostnames are. The net.parseIP() function is used to validate the IP address provided, and net.LookupAddr() does the real work of figuring out what the hostname is.

By default, the pure Go resolver is used. The resolver can be overridden by setting the netdns value of the GODEBUG environment variable. Set the value of GODEBUG to go or cgo. You can do this in Linux with the following shell commands:

export GODEBUG=netdns=go # force pure Go resolver (Default)export GODEBUG=netdns=cgo # force cgo resolver

Here is the code for the program:

package mainimport (   "fmt"   "log"   "net"   "os")
func main() {   if len(os.Args) != 2 { log.Fatal("No IP address ...

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.