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
+12.2k Golang : Get remaining text such as id or filename after last segment in URL path
+48.5k Golang : Upload file from web browser to server
+7.1k Golang : Transform lisp or spinal case to Pascal case example
+9.4k Golang : Play .WAV file from command line
+15.3k nginx: [emerg] unknown directive "ssl"
+14.5k Golang : How to check if your program is running in a terminal
+17k Golang : Get number of CPU cores
+47.8k Golang : Convert int to byte array([]byte)
+9.8k Golang : Format strings to SEO friendly URL example
+16.5k Golang : Get IP addresses of a domain name
+5.9k Golang : Detect variable or constant type