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
+18.7k Unmarshal/Load CSV record into struct in Go
+21.2k Golang : Get password from console input without echo or masked
+14k Golang : convert rune to unicode hexadecimal value and back to rune character
+17.6k Golang : Parse date string and convert to dd-mm-yyyy format
+12.4k Elastic Search : Return all records (higher than default 10)
+8.4k Golang : Convert word to its plural form example
+4.9k Nginx and PageSpeed build from source CentOS example
+17.4k Golang : Get future or past hours, minutes or seconds
+13.1k Golang : List objects in AWS S3 bucket
+18.4k Golang : How to get hour, minute, second from time?
+22.1k Golang : Repeat a character by multiple of x factor