Skip to content

Instantly share code, notes, and snippets.

@c-j-j
Last active March 8, 2017 15:04
Show Gist options
  • Save c-j-j/df314cf4691d390f0cc8 to your computer and use it in GitHub Desktop.
Save c-j-j/df314cf4691d390f0cc8 to your computer and use it in GitHub Desktop.
Go mask network IP
package main
import (
"fmt"
"net"
)
//foo
func main() {
ip := net.ParseIP("127.0.0.1")
fmt.Println(ip)
mask := ip.DefaultMask()
network := ip.Mask(mask)
ones, bits := mask.Size()
fmt.Println("Address is ", ip.String(),
" Default mask length is ", bits,
"Leading ones count is ", ones,
"Mask is (hex) ", mask.String(),
" Network is ", network.String())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment