This commit is contained in:
Stephen McQuay 2018-03-30 09:38:01 -07:00
parent 3a0e9640af
commit d4e4adff48
Signed by: sm
GPG Key ID: 4E4B72F479BA3CE5
1 changed files with 35 additions and 0 deletions

35
main.go Normal file
View File

@ -0,0 +1,35 @@
package main
import (
"fmt"
"net"
"os"
"github.com/apparentlymart/go-cidr/cidr"
)
const usage = "sn <cidr>"
func main() {
if len(os.Args) < 2 {
fmt.Fprintf(os.Stderr, "usage: %v\n", usage)
os.Exit(1)
}
nets := []*net.IPNet{}
for _, sn := range os.Args[1:] {
_, net, err := net.ParseCIDR(sn)
if err != nil {
fmt.Fprintf(os.Stderr, "%v invalid: %v\n", sn, err)
os.Exit(1)
}
nets = append(nets, net)
a, b := cidr.AddressRange(net)
l := cidr.AddressCount(net)
fmt.Printf("%-16s %-16s %10d\n", a, b, l)
}
if err := cidr.NoOverlap(nets); err != nil {
fmt.Fprintf(os.Stderr, "overlaping networks: %v\n", err)
os.Exit(1)
}
}