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
+14.4k Golang : How to pass map to html template and access the map's elements
+5.4k Golang : Return multiple values from function
+8.2k How to show different content from website server when AdBlock is detected?
+12.5k Golang : HTTP response JSON encoded data
+13.8k Golang : Gin framework accept query string by post request example
+13k Golang : Get terminal width and height example
+15.6k Chrome : ERR_INSECURE_RESPONSE and allow Chrome browser to load insecure content
+6.3k Golang : Extract sub-strings
+10.3k Golang : Convert file content to Hex
+16.3k Golang :Trim white spaces from a string
+8.3k Golang : Configure Apache and NGINX to access your Go service example