Last active
March 8, 2017 15:04
-
-
Save c-j-j/df314cf4691d390f0cc8 to your computer and use it in GitHub Desktop.
Go mask network IP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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