Golang net.IP.IsLoopback(), IsMulticast() and IsUnspecified() functions example
package net
Golang net.IP.IsLoopback(), IsMulticast() and IsUnspecified() functions usage example
package main
import (
"fmt"
"net"
)
func main() {
ip4 := "127.0.0.1"
// convert to IP type
ipAdd4 := net.ParseIP(ip4)
fmt.Println("127.0.0.1 is a loopback address: ", ipAdd4.IsLoopback())
fmt.Println("127.0.0.1 is a multicast address : ", ipAdd4.IsMulticast())
fmt.Println("127.0.0.1 is an unspecfied address : ", ipAdd4.IsUnspecified())
}
Output :
127.0.0.1 is a loopback address: true
127.0.0.1 is a multicast address : false
127.0.0.1 is an unspecfied address : false
References :
http://golang.org/pkg/net/#IP.IsLoopback
Advertisement
Something interesting
Tutorials
+7.4k Golang : Accessing dataframe-go element by row, column and name example
+87.7k Golang : How to convert character to ASCII and back
+40.5k Golang : Convert to io.ReadSeeker type
+20.9k Golang : Convert PNG transparent background image to JPG or JPEG image
+31.6k Golang : Get local IP and MAC address
+16.3k Golang :Trim white spaces from a string
+80.6k Golang : How to return HTTP status code?
+24.5k Golang : How to validate URL the right way
+5.9k AWS S3 : Prevent Hotlinking policy
+14.3k Golang : How to shuffle elements in array or slice?
+10.6k Golang : ISO8601 Duration Parser example
+14.3k Golang : Simple word wrap or line breaking example