This recipe will introduce you to how you can translate IP addresses into host addresses and vice versa.
Resolving the domain by IP address and vice versa
How to do it...
- Open the console and create the folder chapter07/recipe03.
- Navigate to the directory.
- Create the lookup.go file with the following content:
package main
import (
"fmt"
"net"
)
func main() {
// Resolve by IP
addrs, err := net.LookupAddr("127.0.0.1")
if err != nil {
panic(err)
}
for _, addr := range addrs {
fmt.Println(addr)
}
//Resolve by address
ips, err := net.LookupIP("localhost...