Golang net.LookupHost() function example
package net
Golang net.LookupHost() function usage example
package main
import (
"fmt"
"net"
"strings"
)
func main() {
addresses, err := net.LookupHost("www.google.com")
fmt.Println(addresses, err)
for i := 0; i < len(addresses); i++ {
segments := strings.SplitAfter(addresses[i], " ")
fmt.Printf("IP address #%d : %s \n", i, segments)
}
}
sample output :
[173.194.126.84 173.194.126.83 173.194.126.81 173.194.126.82 173.194.126.80 2404:6800:4001:802::1013]
IP address #0 : [173.194.126.84]
IP address #1 : [173.194.126.83]
IP address #2 : [173.194.126.81]
IP address #3 : [173.194.126.82]
IP address #4 : [173.194.126.80]
IP address #5 : [2404:6800:4001:802::1013]
Reference :
Advertisement
Something interesting
Tutorials
+6.6k Golang : Warp text string by number of characters or runes example
+9.4k Golang : Launch Mac OS X Preview (or other OS) application from your program example
+10.3k Golang : Convert file content to Hex
+6k PHP : How to check if an array is empty ?
+13.7k Golang : Tutorial on loading GOB and PEM files
+5.6k Golang : Detect words using using consecutive letters in a given string
+6k Golang : How to verify input is rune?
+10.9k Golang : Get UDP client IP address and differentiate clients by port number
+8.5k Golang : How to check variable or object type during runtime?
+17.9k Golang : Login and logout a user after password verification and redirect example
+8.2k Golang : Routes multiplexer routing example with regular expression control
+7.5k Golang : How to handle file size larger than available memory panic issue