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
+6.9k Mac OSX : Find large files by size
+9.5k Golang : Get all countries currencies code in JSON format
+7.1k Nginx : How to block user agent ?
+8.7k Golang : Find duplicate files with filepath.Walk
+14.6k Golang : Missing Bazaar command
+37.5k Golang : Converting a negative number to positive number
+8.8k Golang : Get final balance from bit coin address example
+4.6k Mac OSX : Get disk partitions' size, type and name
+18.5k Golang : Example for RSA package functions
+5.3k Golang : Get FX sentiment from website example
+9.9k Golang : Function wrapper that takes arguments and return result example
+14.7k Golang : Reset buffer example