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 :

http://golang.org/pkg/net/#LookupIP

Advertisement