Here, we will help you to understand how to check Multicast address in Go. We will learn about IsMulticast() method to check Multicast address in go.
IsMulticast() method of net package validates whether ip is a Multicast address or not in Go.
Function prototype:
func (ip IP) IsMulticast() bool
parameters:
ip: Multicast ip address of type net.IP
Return value:
IsMulticast() function in net package returns true if IP address is Multicast IP else false.
Example with code:
package main
import (
"fmt"
"net"
)
func main() {
ip_addr := net.ParseIP("224.0.1.0")
if ip_addr != nil {
is_multicast := ip_addr.IsMulticast()
fmt.Println("Is mutlicast: ", is_multicast)
} else {
fmt.Println("Invalid IP address.")
}
}
Output:
$ go run sample.go
Is mutlicast: true
Example with invalid mutlicast IP address:
package main
import (
"fmt"
"net"
)
func main() {
ip_addr := net.ParseIP("10.2.3.4")
if ip_addr != nil {
is_multicast := ip_addr.IsMulticast()
fmt.Println("Is mutlicast: ", is_multicast)
} else {
fmt.Println("Invalid IP address.")
}
}
Output:
$: go run sample.go Is mutlicast: false
To learn more about golang, Please refer given below link:
https://techieindoor.com/go-lang-tutorial/
References:
https://golang.org/doc/ https://golang.org