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
+25.4k Golang : Convert long hexadecimal with strconv.ParseUint example
+19.6k Golang : Set or Add HTTP Request Headers
+9.9k Golang : Sort and reverse sort a slice of integers
+29.9k Golang : How to get HTTP request header information?
+4.3k Golang : Converting individual Jawi alphabet to Rumi(Romanized) alphabet example
+87.8k Golang : How to convert character to ASCII and back
+19.1k Golang : Clearing slice
+16k Golang : Read large file with bufio.Scanner cause token too long error
+16.8k Golang : Get own process identifier
+9k Golang : Populate or initialize struct with values example
+7.1k Golang : Transform lisp or spinal case to Pascal case example
+7.6k Javascript : Push notifications to browser with Push.js