ipcalc
IP arithmetic utilities for Go, it supports both IPv4/IPv6 addresses.
Installation
go get -u github.com/hazaelsan/ipcalc
Import
import "github.com/hazaelsan/ipcalc"
Package ipcalc
This package provides basic IP arithmetic utilities.
// Get the next IP address
next := ipcalc.NextIP(net.ParseIP("192.0.2.1")) // 192.0.2.2
Note that IP wrapping is entirely possible in most functions
next := ipcalc.NextIP(net.ParseIP("255.255.255.255")) // 0.0.0.0
Package wildcard
This package provides utilities for working with Wildcard Masks, commonly used in Cisco IOS devices.
Wildcard masks are often thought of as "inverse subnet masks", there are some differences:
- Matching logic is reversed from subnet masks, meaning
0
means the equivalent bit must match1
means the equivalent bit does not matter
- 0s and 1s need not be contiguous
Examples below, format is IP/Wildcard:
192.0.2.0/0.0.0.255
matches192.0.2.*
192.0.2.10/0.0.255.0
matches192.0.*.10
192.0.2.1/0.0.255.254
matches192.0.*.{1,3,5,7,...,255}
Use ipcalc.Complement to convert a subnet mask to its wildcard counterpart.