Golang net.LookupIP() function example
package net
Golang net.LookupIP() function usage example
package main
import (
"fmt"
"net"
"strings"
)
func main() {
addresses, err := net.LookupIP("www.yahoo.com")
fmt.Println(addresses, err)
for i := 0; i < len(addresses); i++ {
segments := strings.SplitAfter(addresses[i].String(), " ")
fmt.Printf("IP address #%d : %s \n", i, segments)
}
}
Sample output :
[106.10.138.240 106.10.139.246 2406:2000:e4:200::4001]
IP address #0 : [106.10.138.240]
IP address #1 : [106.10.139.246]
IP address #2 : [2406:2000:e4:200::4001]
Reference :
Advertisement
Something interesting
Tutorials
+39.6k Golang : Remove dashes(or any character) from string
+20.2k Golang : Count number of digits from given integer value
+5.2k Golang : PGX CopyFrom to insert rows into Postgres database
+6.6k Golang : Warp text string by number of characters or runes example
+18.6k Golang : Iterating Elements Over A List
+14.9k Golang : Submit web forms without browser by http.PostForm example
+14.8k Golang : Adding XML attributes to xml data or use attribute to differentiate a common tag name
+8.6k Golang : Convert(cast) []byte to io.Reader type
+17k Golang : How to save log messages to file?
+62.7k Golang : Convert HTTP Response body to string
+12.7k Golang : zlib compress file example
+6k Linux/MacOSX : Search for files by filename and extension with find command