Golang net.ResolveIPAddr() function example
package net
Golang net.ResolveIPAddr() function example
package main
import (
"fmt"
"net"
"os"
)
func main() {
hostname := "www.golang.org"
IPAddr, err := net.ResolveIPAddr("ip", hostname)
if err != nil {
fmt.Println("Error in resolving IP")
os.Exit(1)
}
network := IPAddr.Network()
fmt.Printf("Address : %s \nNetwork name : %s \n", IPAddr.String(), network)
}
Sample output :
Address : 74.125.68.141
Network name : ip
References :
http://golang.org/pkg/net/#ResolveIPAddr
Advertisement
Something interesting
Tutorials
+11.6k Golang : Display a text file line by line with line number example
+15.6k Golang : How to convert(cast) IP address to string?
+15k Golang : Search folders for file recursively with wildcard support
+11.3k Golang : Fix fmt.Scanf() on Windows will scan input twice problem
+16.4k CodeIgniter/PHP : Create directory if does not exist example
+7.6k Golang : Convert(cast) io.Reader type to string
+6.2k PHP : Get client IP address
+80.6k Golang : How to return HTTP status code?
+20.2k Golang : Convert seconds to human readable time format example
+8.1k Golang : Tell color name with OpenCV example
+26.1k Mac/Linux and Golang : Fix bind: address already in use error