Golang net.IPNet type, Contains(), Network() and String() functions example
package net
Golang net.IPNet type, Contains(), Network() and String() functions usage example
package main
import (
"fmt"
"net"
)
func main() {
ipAddress, IPnet, err := net.ParseCIDR("198.162.0.0/16")
if err != nil {
fmt.Println(err)
}
fmt.Println("IP address :", ipAddress)
fmt.Printf("IP Network : %#v\n ", IPnet)
fmt.Println("IPnet.IP : ", IPnet.IP)
fmt.Println("Contains 192.162.0.0 : ", IPnet.Contains(net.ParseIP("192.162.0.0")))
fmt.Println("Network : ", IPnet.Network())
}
References :
http://golang.org/pkg/net/#IPNet
http://golang.org/pkg/net/#IPNet.Contains
Advertisement
Something interesting
Tutorials
+19.3k Golang : Get RGBA values of each image pixel
+30.8k Golang : Download file example
+5.8k Unix/Linux : Get reboot history or check when was the last reboot date
+31.6k Golang : Get local IP and MAC address
+6.3k WARNING: UNPROTECTED PRIVATE KEY FILE! error message
+13.9k Golang : How to check if a file is hidden?
+22.8k Golang : untar or extract tar ball archive example
+9.9k Golang : ffmpeg with os/exec.Command() returns non-zero status
+6.8k Golang : Muxing with Martini example
+13k Swift : Convert (cast) Int to String ?
+15.3k Golang : Get all local users and print out their home directory, description and group id