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
+8.4k Golang : Generate Datamatrix barcode
+7.1k Golang : Get Alexa ranking data example
+16.7k Golang : Gzip file example
+17.1k Golang : XML to JSON example
+40.5k Golang : Convert to io.ReadSeeker type
+6.3k PHP : How to handle URI or URL with non-ASCII characters such as Chinese/Japanese/Korean(CJK) ?
+19.4k Golang : How to count the number of repeated characters in a string?
+5k Golang : Constant and variable names in native language
+10.2k Golang : Check a web page existence with HEAD request example
+5.6k PHP : Convert string to timestamp or datestamp before storing to database(MariaDB/MySQL)
+18.1k Golang : Check if a directory exist or not
+27.4k Golang : Convert CSV data to JSON format and save to file