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
+11.6k Golang : Display a text file line by line with line number example
+4.7k Linux/MacOSX : How to symlink a file?
+18.8k Golang : Delete duplicate items from a slice/array
+51.4k Golang : Check if item is in slice/array
+13.1k Golang : Handle or parse date string with Z suffix(RFC3339) example
+51.1k Golang : Disable security check for HTTPS(SSL) with bad or expired certificate
+6k Linux/MacOSX : Search for files by filename and extension with find command
+17.5k Golang : Find smallest number in array
+6.9k Golang : How to solve "too many .rsrc sections" error?
+15.4k Golang : invalid character ',' looking for beginning of value
+5.6k Golang : Detect words using using consecutive letters in a given string