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
+9.1k Golang : Get login name from environment and prompt for password
+12.5k Javascript : Prompt confirmation before exit
+5.6k Golang : Derive cryptographic key from passwords with Argon2
+29.7k Golang : Get local IP and MAC address
+13.7k Golang : How to check if IP address is in range
+4.4k Javascript : How to loop over and parse JSON data?
+20.1k Golang : Upload big file (larger than 100MB) to AWS S3 with multipart upload
+5.2k Golang : How to get capacity of a slice or array?
+7k Golang : Append and add item in slice
+12k Golang : Date and Time formatting
+3.9k Unix/Linux : How to pipe/save output of a command to file?
+16.4k Golang : Read data from config file and assign to variables