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
+13.5k Golang : How to get year, month and day?
+14k Golang : concatenate(combine) strings
+16.8k Golang : Get own process identifier
+8.4k Golang : Ackermann function example
+16k Golang : Generate universally unique identifier(UUID) example
+15.2k JavaScript/JQuery : Detect or intercept enter key pressed example
+9.8k Golang : Get current, epoch time and display by year, month and day
+16.6k Golang : Generate QR codes for Google Authenticator App and fix "Cannot interpret QR code" error
+11.3k Golang : How to flush a channel before the end of program?
+18.5k Golang : Send email with attachment
+6.3k Golang : Detect face in uploaded photo like GPlus