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
+8.3k Golang : Auto-generate reply email with text/template package
+8.7k Golang : Find duplicate files with filepath.Walk
+22.7k Golang : Strings to lowercase and uppercase example
+6.5k Golang : Calculate diameter, circumference, area, sphere surface and volume
+9.9k Golang : Sort and reverse sort a slice of integers
+10.4k Golang : Simple Jawi(Yawi) to Rumi(Latin/Romanize) converter
+24.1k Golang : Upload to S3 with official aws-sdk-go package
+6.3k Javascript : Generate random key with specific length
+9.7k Golang : interface - when and where to use examples
+87.8k Golang : How to convert character to ASCII and back
+7.4k Golang : Check to see if *File is a file or directory