Golang net.IP.IsGlobalUnicast() function example

package net

Golang net.IP.IsGlobalUnicast() function example

 package main

 import (
 "fmt"
 "net"
 )

 func main() {

 // google.com ip version 4 and 6 addresses
 // from https://www.socketloop.com/tutorials/golang-resolve-domain-name-ip4-ip6

 ip4 := "74.125.130.105"

 // convert to IP type
 ipAdd4 := net.ParseIP(ip4)

 fmt.Println("Google.com ip4 address is a global unicast address : ", ipAdd4.IsGlobalUnicast())

 }

Output :

Google.com ip4 address is a global unicast address : true

Reference :

http://golang.org/pkg/net/#IP.IsGlobalUnicast

Advertisement